use strict; use warnings; local $SIG{ALRM} = sub { die 'timeout' }; alarm(3); my $result = eval { }; alarm 0; if ( !defined($result) ) { print "Oh well, I didn't need that anyway...\n"; }