in reply to Printing Code

I would probably use a here-doc with single quotes:
open(FILE, ">test.sh") or die "Couldn't open test.sh."; print FILE <<'EOS'; #!/usr/bin/sh echo 'This is a test' EOS close(FILE); print "File written";
In Perl, you can prevent the contents of a string from being interpolated by quoting it with single quotes, or using the q// quote-like operator. See perlop (Quote and Quote-like Operators) and perldata (here-doc).

Impossible Robot