use strict; use warnings; open my $bh, "<", $B_file or die "$0: open $B_file: $!"; my %bHash; # slurp text file B # could generate a unique key consisting of field 0 and 11, # but never mind. foreach (<$bh>) { my @text=split(/\t/); $bHash{$text[0]} = $text[11]; } close $bh; open my $ah, "<", $A_file or die "$0: open $A_file: $!"; # read in text file A foreach (<$ah>) { my @text = split(/\t/); if ($bHash{$text[3]} eq $text[11]) { # we have a match, print it print join( "\t", @text[1..3]),"\n"; } } close $ah;