my $string = join " ", keys %hash1; foreach my $item ( keys( %hash2 ) ) { print "$item matches" if ( $string =~ /\b$item\b/i ); }