for (;;) { ... if ($COMPLETE) { show_status(); print "finished\n"; last; } } close $log or die "Cannot close file '$log_file': $!";