nbezalla:
Okay ... now that I've answered your second question, I guess I should address the first one.
Generally, when I debug a long-running while loop, I'll use one (or more) of the following techniques:
If each iteration is relatively quick and simple, I'll first use the perl debugger to step through the first few iterations to get a feel for things.
If there are plenty of alternate execution paths, I'll set a breakpoint in *all* of them, then start the program. As I reach each new breakpoint, I'll step through to the end of the loop, looking for something odd. When I hit the end of the loop, if I found nothing interesting in that path, I'll remove the breakpoint that I tripped and continue execution. After a while, you'll usually reach the point where the fault occurs relatively quickly.
Sometimes, I'll just pepper the loop with print statements showing the values of variables I'm concerned about, to see what's happening.
If the fault seems to occur with the same data each time, then I'll use the debugger and set the variables up to cause the fault immediately, then step through the code and see where my bug is.
I hope this is useful...
...roboticus