http://www.perlmonks.org?node_id=699424


in reply to How to generate files based on some special character?

Or (just for kicks):

perl -pe"s/^</#EOF\ncat<<'#EOF'>/" large_file | sh