http://qs1969.pair.com?node_id=293088


in reply to enforce timeout in loop

Follow the example in the perldoc page for alarm. Change your for loop to look like:
foreach my $sleepval (@sleepvals) { eval { local $SIG{ALRM} = sub { die }; alarm 3; sleep($sleepval); }; print strftime "%H:%M:%S", localtime; print "\n"; }