in reply to How to 'escape' a character in a string?

Use the \Q...\E quoting mechanism:
s/\Q$delim\E/\\$delim/g

See perlre for details.