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