use strict; use warnings; use File::Slurp qw/read_file/; my ( $hash1, $hash2 ) = @ARGV or die $!; my %hash1 = map { /(.+?),(.+)/; $1 => $2 } grep /.,./, read_file $hash1; my %hash2 = map { /(.+?),(.+)/; $1 => $2 } grep /.,./, read_file $hash2; for my $key2 ( sort keys %hash2 ) { for my $key1 ( sort keys %hash1 ) { print "$key2\t$hash2{$key2}\t$key1\n" if $hash1{$key1} =~ /\b$hash2{$key2}\b/; } }