LOOP: for (1 .. $max_loops) { # your refinement loop if ($better) { # update best next LOOP; } # end of your refinement loop last; }