use Regexp::Assemble; use List::Util qw(reduce); # XXX why have a hash if its values are not used? 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 } ($string =~ /\b($key_re)\b/gi); print "Found '$match' in '$string'\n" if defined $match; }