$SIG{ALRM} = sub { print "...timeout"; next READING; }; my $number = 1; READING: while ( $number < 10 ) { eval { alarm(3); print $number; if ( $number == 3 ) { sleep 4; } # This is to simulate the delay the routines may generate... $number++; print "\n"; } } if ($@) { # this I copied from the Camel book, but not sure about what it means and if it is really necessary in this case... (I donīt want to 'die'; i just want to go to the 'next' iteration.) if ($@ =~ /timeout/) { # timed out; do what you will here } else { alarm(0); # clear the still-pending alarm die; # propagate unexpected exception } }