The simplest might be just to prefix all non-word and non-space characters in the pattern by a \:
$pattern=~ s/([\W\S])/\\$1/g;Originally posted as a Categorized Answer.
In reply to Re: How to prevent metacharacter interpolation
by mirod
in thread How to prevent metacharacter interpolation
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |