use List::Util qw(max); my $maxprofit = max @profit; our $index = grep { $profit[$_] eq $maxprofit } 0..$#profit;