my %csahash; my $line=<>; while($line=<>){ if($line=~ /\b(\d\w{3})\b/){ $csahash{$1}++; } } %cathhash; my $line2=<>; while($line2=<>){ if($line2=~/\b(\d\w{3})\b/){ $cathhash{$line2}++; } } foreach my $key(keys %csahash){ if(defined $cathhash{$key}){ print "$key matches. It's values are $csahash{$key} and $cathhash{$key}\n"; } }