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

pos() = pos() - 1;? ow! Use zero-width matches.
my $phrases_pat = join '|', map quotemeta, @phrases; $in =~ s/(?<!\S)($phrases_pat)(?!\S)/#$1#/g;

Bonus: In addition to being much simpler, this should be faster since much less work is outside the substitution, in matching and in replacing.