while <$FILE_1> { $file1{$_}=0; } while <$FILE_2> { my ($match_val) = split(/\s+/, $_); #split on whitespace print $_ if defined $file1{$match_val}; }