use strict; use warnings; open(FH1,"file1.txt"); open(FH2,"file2.txt"); my @array=; chomp @array; while(my $var=){ chomp $var; my ($first,$second)=split(/\s+/,$var); my @grepped= grep {/\Q$second\E/} @array; print "$first\t$grepped[0]\n"; }