in reply to while loop not exiting?

Is there more code after the loop?

Try adding a $|=1 to the top of your code. Just a hunch.

Otherwise the code looks ok to me.
"But what of all those sweet words you spoke in private?"
"Oh that's just what we call pillow talk, baby, that's all."