use Regexp::Assemble; use Regexp::Exhaustive qw(exhaustive); use List::Util qw(reduce); my @keys = map { quotemeta } keys %hash; my $key_re = Regexp::Assemble->new->add(@keys)->re; for my $string (@strings) { my $match = reduce { length($a) > length($b) ? $a : $b } exhaustive($string => qr/\b($key_re)\b/i); print "Found '$match' in '$string'\n" if defined $match; }