my $max_count = 10; for my $elem( splice( @array, 0, $max_count ) ) { # do whatever }