my $timeout = 3 my $timedout = 0; my $oops = 0; my $error; my $stime; my $etime; eval { local $SIG{ALRM} = sub { die "timeout\n" }; # die out of eval statement not entire program alarm $timeout; $stime = time; # make a note of the time now $result = $ua->request($req); # make request of website $etime = time; # make a note of the time now alarm 0; }; if ($@) { if ($@ eq "timeout\n") { $timedout = 1; } if ($@ and $@ ne "timeout\n") { $oops = 1; } # if there was an error in the eval and it wasn't the alarm } $error = $timedout || $oops; my $dtime = $etime - $stime; # figure out the time taken for the request if (!$error) { open(TEST,">/var/tmp/t4.txt"); print TEST "http result\n"; # here I get told that the request took 10 seconds and my time out is 3 seconds print TEST $result->status_line." : $dtime secs taken, timeout = $timeout\n"; # print TEST "ok\n"; close(TEST); } else { open(TEST,">/var/tmp/t4.txt"); if ($oops) { print TEST "oops error occurred: $@\n"; } else { print TEST "timeout\n";} close(TEST); }