sub threadProc { my $code = shift; for(1 .. 5 ){ my @rv = eval { $code->( @_ ); }; if( $@ ) { ## log errors if applicable ## next if retrying makes sense. ## last if not. tprint "$@; retrying"; } else { return @rv; ## return any return values if applicable. ## think about scalar/list/void context. } } } my @threads = map threads->new( \&threadProc, \&processrefsthread, $Q ), 1 .. $T;