... if you factor out the common \s.But if @phrases was something like qw(foo bar baz) then the final substitution regex would be equivalent tomy $string = join '|', map {quotemeta} @phrases; $sentence =~ s/(\s$string\s)/#$1#/g;
Adding a non-capturing sub-grouping should do the trick:
$sentence =~ s/(\s(?:$string)\s)/#$1#/g;
In reply to Re^2: map function use
by AnomalousMonk
in thread map function use
by newbio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |