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

Try to use the quotemeta operator (or, equivalently, the \Q ... \E tags) on your search list. It should remove all problems of this sort.

Replies are listed 'Best First'.
Re^5: Escape special characters for a LaTeX file
by AnomalousMonk (Archbishop) on Dec 16, 2014 at 03:59 UTC

    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.

      Interesting, I did not know that.