$SIG{ALRM} = sub { die "timed out" }; eval { alarm(60); # give it 60 seconds $response = $useragent->simple_request($request,\&callback,2048); alarm(0); }; # now look for "timed out" in $@ if ($@ =~ /timed out/) { # do something } #### undef $useragent if $@ =~ /timed out/;