eval { local $SIG{ALRM} = sub { die "timeout" }; alarm($timeout); connect(SOCKET, $paddr) || error(); alarm(0); }; #### #!perl eval { local $SIG{ALRM} = sub { die "timeout" }; alarm(1); error(); # not found -> dies alarm(0); }; print "\$@: $@\n" if $@; # do something that takes longer than a sec, # without itself being implemented via SetTimer() rand for 1..2e7; __END__ H:\PM>perl 759131.pl $@: Undefined subroutine &main::error called at 759131.pl line 6. Terminating on signal SIGALRM(14)