open(FILE1, $ARGV[0]) or die "Cannot open the file: $!"; my %hash1 = split ' ', do{ local $/; }; close FILE1; open(FILE2, $ARGV[1]) or die "Cannot open the file: $!"; while() { my ($key) = split; exists $hash1{$key} and print "$key $hash1{$key}\n"; } close FILE2;