Btw, there is still a problem in there. You can't use $N in a while loop. It loses the value after the first time through, so you need to store it.