in reply to for loop

When you run your program, what are the results you get? Not what you want, right? What do you have to change to get what you want?

In otherwords, try doing that problem by hand. Write some pseudo-code to implement your solution. Then translate that into Perl.