Just wrap it in an outer loop, iterating over all five files:
for my $file ( @five_files ) {
open my $fh, '<', $file or die "Unable to open $file: $!";
my @file = <$fh>;
foreach (@file) {
my @temp = split(/\t/, trim($_));
push(@output, $temp[0] . "\t" . $temp[1] . "\n");
}
foreach(uniq(@output)) {
print $OUTPUTFILE $_;
}
}
Since you're interested in just the first two elements of @temp
, the foreach @file
loop can be simplified:
my @temp = split /\t/, trim($_), 2;
push @output, @temp, "\n" ;