use v5.10; use WWW::Mechanize::Firefox; use strict; use warnings; my $mech = WWW::Mechanize::Firefox->new(); $mech->update_html(< function myFunction() { alert("Hello World!"); } HTML sleep 2; $mech->eval_in_page( 'myFunction();' );