$str = 'user input'; $str =~ s/^$/ /gm; # add a space to each blank line print <<"EndOfGeneratedCode"; print <<''; $str EndOfGeneratedCode