in reply to Help with a programming problem.

Your for loops are much better written:

for my $count (0 .. $i1 - 1) {

which both avoids the immediate problem and makes the action of the loop much clearer (assuming that you recognise the range operator '..', or at least can infer what it does).

True laziness is hard work