my $x = 10; # the number of iterations to do between each sync my $int = 10; # the desired interval between actions my $y = 0; # another iteration limit, for catching up foo: { my $time = time(); for (my $i = 0; $i <= $y; $i++){ # catch up with real time from the last loop action(); # perform the action } for (my $i = 0; $i < $x; $i++){ action(); sleep $int; } my $ntime = time(); $y = int ( ($ntime - $time - $x * $int) / $int ); # calculate how many we missed, and round down redo foo; }