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

quotemeta
my $delim = quotemeta '|'; my $s = 'This is my string that has a | in it.'; $s =~ s/($delim)/\\$1/g; print "$s\n"; __END__ This is my string that has a \| in it.