second.txt 9,/vol/elephant,fourfeet 1999,/vol/dolphin,fish 10,/vol/cat,feline 1111,/vol/goldfish,fish 2222,/vol/spider,arachnid 5555,/vol/camel,dromedary #!/usr/bin/perl use strict; use warnings; sub get_file { open my $FILE, '<', shift or die $!; return map {$_ => $_} <$FILE>; return map {$_->[0] => $_->[1]} <$FILE>; } my %a = get_file '/tmp/first.txt'; my %b = get_file '/tmp/second.txt'; { no warnings 'uninitialized'; print "$_\n" for grep {$_} @a{keys %b}; }