my @a = ( 1 .. 1_000_000 ); # some large array my $want = 5843; my $index = 0; ++$index until $a[$index] == $want or $index > $#a;