in reply to Looping made easy...

Perhaps one of the problems you're running into is variable scope. If you use the global variable $i for all of your loop counters, they'll end up stepping all over each other if one loop calls another, since they're sharing a counter variable. If you localize your counter variables with my, each loop will have a copy of its own (even if they all happen to have the same name). For example, your loop could be written as:
for(my $i=0;$i<=89;$i++) { ... }
or
foreach my $i (0..89) { ... }