Question: I am new at scripting and I am trying to concatenate multiple files, whose paths are listed a text file and output a combined gzip file. 
for example list file - File\_list.txt contains these file paths 

```
/data/path/file1.txt
data2/path2/file2.txt
....file3.txt
....file4.txt

```

So far my code is for all files listed in a local directory ( outputs only combined file not gzipped): 

```
#!/usr/bin/perl

use strict;
use File::Slurp;

my $directory = 'Users/xyz/Documents/';

opendir(dir, $directory) or die $!;
my @files = readdir(dir);
closedir dir;

my $outfilename = 'Combined.fastq'

my $outfilesrc = undef;

foreach (sort @files){ 
  $outfilesrc.= File::Slurp::slurp("$basedir/$_");
}

open(OUT, "> $basedir/$outfilename") or die ("Can't open for writing: 
  $basedir/$outfilename : $!");
print OUT $outfilesrc;
close OUT;

exit;

```

Can someone please share how to read the files using this list rather than one single directory? 
I know it's much easier in simple bash but i am trying to create a module for a pipeline so need this in Perl. 
Thanks!

Answer: 
You don't seem to do anything with a zip file. I can't even begin to guess (`Archive::Zip` is pretty good though).

For concatenating a bunch of files, you can make use of the `ARGV` or `<>` filehandle. 

```
#!/usr/bin/env perl
use strict;
use warnings;

open ( my $combined, '>', 'combined.fastq') or die $!; 

select $combined; 
print while <>; 

close $combined; 

```

Should do the trick - you open an output file, select it as the default place to print, and then print every line captured in `<>` - which is all the data in any files specified on the command line, or piped data. 

So invoking this script as `merge.pl *.txt` will take all the text files (in the current directory) and merge them into the combined file. 

As you've got an input list - that's as simple as:

```
open ( my $list_of_files, '<', 'file_list.txt' ) or die;
chomp ( @ARGV = <$list_of_files>);
close ( $list_of_files ); 

```

This will accomplish the same result overall.
Thanks a lot for your replies - The script runs well now, being new at perl it sounded difficult one to me. Just posting my code below - 

```
#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp;
use IO::Compress::Gzip qw(gzip $GzipError);

my @data = read_file('./File_list.txt');
my $out = "./test.txt";

foreach my $data_file (@data)

{
    chomp($data_file);
    system("cat $data_file >> $out");
}
my $outzip = "./test.gz";
gzip $out => $outzip;

```