{ alarm 2; ## don't set this globally! local $SIG{ALRM} = sub { die "timed out" }; eval { callfc() }; ## continue to next iteration if timed out next if $@ and $@ =~ /^timed out$/; }