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$/; }