in reply to All the other Characters

I think the safest way to avoid problems with special characters is to use a single-quoted here-doc. There are no special characters in a single-quoted here doc:
print <<'EndOfText'; Hello! my name is "Bob". This is an old\new text. EndOfText
Now all you have to worry about is a line in the text matching the here-doc terminator. Here's a way to avoid that problem, in the script that creates the code:
$str = 'user input'; $str =~ s/^$/ /gm; # add a space to each blank line print <<"EndOfGeneratedCode"; print <<''; $str EndOfGeneratedCode
With a null terminator, a here-doc ends at the first empty line; the substitution replaces all the empty lines in the user's input with lines containing a single space.