my @data; for my $file (qw(this.txt that.txt)) { open my $fh, '<', $file or die $!; push @data, []; while( <$fh> ) { push @{$data[-1]}, $_ if /\n\z/ && ! /^>/; } } #### @data = read_files( qw(this.txt that.txt) ); sub read_files { my @data; for my $file ( @_ ) { open my $fh, '<', $file or die $!; push @data, []; while( <$fh> ) { push @{$data[-1]}, $_ if /\n\z/ && ! /^>/; } return @data; }