my $string = q~+?.*^$()[]{}|\\~; $text =~ s/([\Q$string\E])/\\$1/g; print $text;