for each $country_key (keys %$countries) { $fork_countries->start and next; ... foreach $case_no (keys %$case) { $fork_cases->start and next; #do DBIx stuff to get random $ff_profile / avoid race condition $ff_port = 42420 + $ff_profile; &myMain($ff_profile, $ff_port); $fork_cases->finish; } $fork_cases->wait_all_children; $fork_countries->finish; } $fork_countries->wait_all_children; sub myMain { $mech = WWW::Mechanize::Firefox->new( launch => ['firefox','-P',$ff_profile,-no-remote'], repl => "localhost:$ff_port", bufsize => 10_000_000, tab => 'current', autoclose => 1 ); $mech->get($url); $url = $new_url; ### KLUDGED HERE ### # # $temp = $mech->uri; # (undef, $uri) = split(/(\?.*)/, $temp); # $url .= $uri; # ### $html = $mech->content; $mech->get($url); #or eval, click(), etc. $html .= $mech->content; #open temp filehandle and print $html #(temp filenames padded with String::Random) $mech->get(temp_filename); $png = $mech->content_as_png; #add png to PDF with PDF::API2 #write PDF file }