use List::Util qw(sum); while (1) { if (sum(times) > 30) { # have I used more the 30 CPU seconds? fork and exit; # carry on, my wayward son, there'll be peace when you are done... } ... rest of processing here ... }