This should do what you want:
#!/usr/bin/perl
# http://perlmonks.org/?node_id=1151834
use strict;
use warnings;
open my $FH1, '<', shift or die $!;
my %keys;
while (<$FH1>) {
chomp;
$keys{$_}++;
}
close $FH1;
open my $FH2, '<', shift or die $!;
while (<$FH2>) {
chomp;
my ($record, $key) = split ',', $_, 2;
print "match: $key record: $record\n" if exists $keys{$key};
}
close $FH2;
Your code looks like something you've copied from somewhere without really understanding it. I'd advise against doing that: cargo cult code like that might be inefficient, might not actually do what you want, or it might even do damage to your system or data without you knowing it.