use strict; use warnings; my $str = 'A string with a "double quoted" string in it'; (my $quoted = $str) =~ s/\"/\\\"/g; print "$str\n$quoted\n"; #### A string with a "double quoted" string in it A string with a \"double quoted\" string in it