my $max_retry =3; RETRY: while (my $n_attempt=0, $parameter=<>) { my $req = POST 'http:/...blah..../', [ action => '/db/', param => "$parameter", type => 'submit', value => 'Search', ]; my $res = $ua->request($req); # idea is to concentrate the "it didn't work" code to # right here unless ($res->is_success) ##1 of 5,000 case## { $n_attempt++; print STDERR "attempt # $n_attempt for $parameter\n"; print STDERR "$parameter ERROR: Try# $n_attempt of $max_retry: ". $res->status_line . "\n"; sleep(1); redo RETRY if $n_attempt <= $max_retry; print STDERR "$parameter ERROR: Try# $n_attempt of ". "$max_retry FAILED: ". $res->status_line . "\n"; next; #we "Give up" at this point! And read next #parameter from <> } ### this is the "good machine case..." print $res->as_string if DEBUG_RAW; ......or whatever.... }