Either study what the JS bit does and do it in your script yourself, if possible, or use something like
Selenium and its Perl facilities. Selenium harnesses Firefox. Setting it up can be challenging, but it should be smooth sailing afterwards. See
Re: General web application testing advice sought. for a reference from
a wiser monk.