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

... all "0" are escaped.

That's because '0' (zero) is part of the character class: the value of  $% happens to be 0 at that point | the moment of regex compilation. Please see my update to the above.

Update: E.g.:

c:\@Work\Perl\monks\marek1703>perl -wMstrict -le "my $s = '-#-$-%-&-~-_-}-{-^-0-$%&~_}{^0'; print qq{'$s'}; ;; $s =~ s{ ([#\$%&~_{}^]) }{\\$1}xmsg; print qq{'$s'}; " '-#-$-%-&-~-_-}-{-^-0-$%&~_}{^0' '-\#-\$-\%-\&-\~-\_-\}-\{-\^-0-\$\%\&\~\_\}\{\^0'
and also (no capture):
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'