my $j = 0; while (1) { for (my $i = 0; $i < 10 && $j < @found; $i++) { $j++; print $found[$j], "\n"; } # do something last if ($j == @found); }