$cmd = qq{cat <<-ENDOFMESSAGE \none \ntwo \nthree \nENDOFMESSAGE}; print ($cmd =~ s/\n/\\n/gr); print "\n"; # cat <<-ENDOFMESSAGE \none \ntwo \nthree \nENDOFMESSAGE print `$cmd`; # one # two # three