... my $stop_time = time + 60 * 60 * 7; # now + 7 hours while (1) { do_work; last if time > $stop_time; } ...