in reply to Code optimization help and troubleshooting

... reducing the code ...

Instead of a million
    print AA "HTML string \n";
statements, consider a here-doc:

print AA <<"EndOfHTML"; <html>blah blah blah</html> ... <stuff>yada $scalars and @arrays can be interpolated in some cases yad +a</stuff> EndOfHTML
See Quote and Quote-like Operators and especially Quote-Like Operators (see  <<EOF at the end of the latter section (update: just before the Gory details of parsing quoted constructs section)).