is not valid Perl - you forgot a closing round bracket. I'm not entirely sure there there's no circumstance under which this might mistakenly parse. Assuming that's not the problem, where do $available_machine and $request_file_exists get changed? I don't see them altered in the loop. If they're being changed in a part of the code you left out, you may have a fencepost error (ie your loop conditions do not get changed as early as you're expecting).