Separate out your javascript into another file and use <script src="/path/to/your/file.js"/> instead. This allows the browser to cache your JS files.
Learn some Javascript. JS is, imho, a better language than Perl for many reasons. It's still a bit immature, but has features I wish I could have in Perl.
My criteria for good software:
Does it work?
Can someone else come in, make a change, and be reasonably certain no bugs were introduced?