my $loopcount = 0; 1 while (! $process->Wait(1000) and ! -e $the_file and $loopcount++ < $timeout); if ($loopcount >= $timeout) { ... fead up with waiting. } elsif (-e $the_file) { ... it errored out } else { ... it did its work }