#!/usr/bin/perl -w use strict; use Thread::Pool; use WWW:Mechanize; my %check :shared = ('success', 0, 'fail', 0, 'exit', 0); my $pool = Thread::Pool->new( { optimize => 'memory', workers => 1, do => \&request, } ); for(1..10){ $pool->job(); $pool->add; { print "Please type 'exit' to quit: "; chomp ($_=); if($_=~/exit/i){ $check{exit} = 1; $pool->shutdown;} print "success: $check{success}\tfailed: $check{fail}\n"; sub request{ my $flag = 0; my $mech = WWW::Mechanize->new(autocheck => 1); $mech->get('http://example_server.com/login.php'); $mech->submit_form( form_number =>1, fields =>{ username => 'testuser' password => '123qwe' } ); if($mech->uri() =~/home/i){ #check if login if successful $check{success}++; $flag = 1; } else { $check{fail}++;} while($check{exit} != 1 && $flag == 1){ $mech->follow_link( url_regex => qr/nextpage/i); $mech->get('http://example_server.com/home'); } }