in reply to cgi and javascript

Yes, you can write Javascript from Perl, just like any other page content. Work out what your Javascript code will be in the page and which parts will need to be generated by the script, and cycle through your content for those parts. Of interest will be printing in blocks:
print <<OUT; Javascript goes here OUT
This allows you to print large sections of HTML / Javascript without using messy print statements.