in reply to Re: map function use
in thread map function use

... if you factor out the common \s.
my $string = join '|', map {quotemeta} @phrases; $sentence =~ s/(\s$string\s)/#$1#/g;
But if  @phrases was something like  qw(foo bar baz) then the final substitution regex would be equivalent to
    $sentence =~ s/(\sfoo|bar|baz\s)/#$1#/g;
in which a leading space is associated only with  foo and a trailing space only with  baz and nothing with  bar.

Adding a non-capturing sub-grouping should do the trick:
    $sentence =~ s/(\s(?:$string)\s)/#$1#/g;