in reply to Ajax and Perl 5.6 and heredocs

As Corion said, you are really contemplating two independent tasks.

Changing the here-doc to template toolkit will help you in the long run to maintain your site and should be rather straightforward (if the source is well-designed). TT has all the important control structures as well, so a 1 to 1 translation is possible

For the javascript there are a few libraries available that might help you in your task, for example Ext JS, Dojo or jQuery.