#!/usr/bin/perl use strict; use warnings; my @times = (2, 4, 3, 1, 2, 5); select((select(STDOUT), $|=1)[0]); TIME: for my $time_to_wait (@times) { print "Time to wait is: $time_to_wait\n"; local $@; eval { # Don't handle even numbers. die '__NOT_FATAL__' if !($time_to_wait % 2); this_will_die_if_true($time_to_wait); 1; } or do { if($@ && $@ =~ /__NOT_FATAL__/) { next TIME; } print "Something went boom! ($@)\n"; }; print "Sleeping for $time_to_wait seconds ... "; sleep $time_to_wait; print "Done.\n"; } exit 0; sub this_will_die_if_true { my ($arg) = @_; $arg //= 0; $arg && die "We died!"; return; }