foreach $j (@j) { alarm 2; ## don't set this globally! local $SIG{ALARM} = sub { die "timed out" }; eval { callfc() }; ## continue to next iteration if timed out next if $@ and $@ =~ /^timed out$/; } #### $ t21.pl 0 1 Terminating on signal SIGALRM(14)