Also, don't forget to turn on autoflush (
$| = 1; will do that). Otherwise, your perception of what the program is doing is going to be skewed by output buffering.
Update: I re-read the thread and realized my reply doesn't address the issue. However, I feel it's still good general advice for something like this.
---
It's all fine and dandy until someone has to look at the code.