use strict; my @end = ( 3, 3, 3 ); my @start = ( 0, 0, 0 ); my @index = @start; LOOP: while (1) { print "this is loop position [ @index ] \n"; for my $q ( reverse 0 .. $#start ) { $index[$q]++; last unless $index[$q] >= $end[$q]; last LOOP unless $q; $index[$q] = $start[$q]; } } print "done \n";