use strict; use warnings; my $data1 = <) { chomp; my ($key, $tail) = split ' ', $_, 2; $data2Hash{$key} = $tail; } close $infile2; open my $infile1, '<', \$data1; while (<$infile1>) { chomp; my ($key, $tail) = split ' ', $_, 2; if (exists $data2Hash{$key}) { print "Matched $key: $data2Hash{$key}, $tail\n"; } }