eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; # your code here alarm 0; }; if ($@ and $@ !~ /alarm clock restart/) { die }