eval { local $SIG{'ALRM'} = sub{die 'timesup';}; alarm 2; # Now do something as a pause while(1) { select(undef,undef,undef,0.01); } alarm 0; }; if($@ =~ 'timesup') { # Call timeout code }