in reply to while loop almost correct

Your script ignores the the first $reply given.

HTH