my $max_count = 10; for my $idx ( 0 .. $#array ) { # do whatever last if $idx >= $max_count; }