in reply to How to prevent metacharacter interpolation

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.