in reply to How to 'escape' a character in a string?
s/\Q$delim\E/\\$delim/g [download]
See perlre for details.