sub timeout_func{ # The first parameter is the timeout time my $TIMEOUT=sprintf("%s",$_[0]); # The second parameter is the address of the function we # need to perform a timeout for my $ADDRESS=sprintf("%s",$_[1]); # The third parameter is the first parameter of the # function we need to run my $FIRST=sprintf("%s",$_[2]); eval{ #set the callback for the alarm signal local $SIG{ALRM} = sub { die ("ETIME\n") }; #specify the alarm timeout alarm($TIMEOUT); #call the funtion that the calling code has provided #the address of via the \& mechanism #if we came back with in the time limit, reset the alarm alarm(0); }; } # timeout_func timeout_func(120,\&funtion_that_might_hang,<1st param to funtion_that_might_hang>);