my $substitute = qq{throw \("$1"\)}; #### my $substitute = q{qq{throw ("$1")}}; # and later substitute like this $line =~ s/$regex/$substitute/ee;