in reply to Re^4: Escape special characters for a LaTeX file
in thread Escape special characters for a LaTeX file

Another way to completely defeat scalar or array interpolation in regexes (as in strings) is by use of  ' (single-quote) delimiters for the  s/// substitution:

c:\@Work\Perl\monks\marek1703>perl -wMstrict -le "my $s = '-#-$-%-&-~-_-}-{-^-0-$%&~_}{^0'; print qq{'$s'}; ;; $s =~ s' (?= [#$%&~_{}^]) '\\'xmsg; print qq{'$s'}; " '-#-$-%-&-~-_-}-{-^-0-$%&~_}{^0' '-\#-\$-\%-\&-\~-\_-\}-\{-\^-0-\$\%\&\~\_\}\{\^0'
(This applies also to  m// and  qr// operators.) See perlop.

Replies are listed 'Best First'.
Re^6: Escape special characters for a LaTeX file
by Laurent_R (Canon) on Dec 16, 2014 at 08:12 UTC
    Interesting, I did not know that.