This program is expecting to be called like this:
$ program.pl input1.dat input2.dat output.dat
So you currently need to to give it two input files and an output file.
If you want to change it to process more than two input files, then you'll (presumably) still need to pass it an output file as well. Something like this, perhaps:
$ program.pl *.fastq.gz output.dat
And then inside your code, you can write:
my $outfile = pop @ARGV; my @infiles = @ARGV;
You would also have to change the code that opens filehandles as it's currently hard-coded to use two input files and an output file.
But, here's something else to consider. Perhaps, don't open any files at all. Instead, write your code as a Unix-style filter.
$ program.pl input_files* > output.dat
Then simply read from
<> (the empty file input operator) and write to