use strict; use warnings; print scalar localtime, "\n"; eval { $SIG{__DIE__} = sub { alarm(0) }; $SIG{ALRM} = sub { die "timeout" }; alarm(2); system('sleep 5'); }; print $@ if $@; print scalar localtime, "\n";