Do not generate your JavaScript from Perl. That's no different from generating HTML from Perl, which is very 1990'ish.
Very often JavaScript stays static and shouldn't be changed on each request (think of your functions/classes, they don't change). You can put such code into separate .js files and benefit from caching of static files.
If you still need to conditionally generate JavaScript parts in your HTML output (such as variables interpolation) Template::Toolkit comes to the rescue the same way it helps to generate HTML.
Another suggestion, to reduce the number of typed characters and add more readability is to use CoffeScript or any similar language, which translates to more verbose JavaScript.