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

$text =~ s![#$%&~_}{^]!\\$&!g;

But only one character is not escaped: "%"

The sequence  $% is interpreted as the Perl special variable  $% (see perlvar) and its current value is interpolated. Try  [#\$%&~_}{^] (escaping the  $ character) instead.

Update: E.g.:

c:\@Work\Perl\monks\marek1703>perl -wMstrict -le "my $sans_esc = qr/[#$%&~_}{^]/; print $sans_esc; ;; my $with_esc = qr/[#\$%&~_}{^]/; print $with_esc; " (?^:[#0&~_}{^]) (?^:[#\$%&~_}{^])