s/\Q$delim\E/\\$delim/g [download]
See perlre for details.
In reply to Re: How to 'escape' a character in a string? by moritz in thread How to 'escape' a character in a string? by VingInMedina