my ($largest_index, $largest_value) = (-1E6, undef); #make sure $largest_index starts below the lowest possible #value you can get for my $data (@some_big_long_list){ my $this_index = index_from($data); if ($this_index > $largest_index){ $largest_index = $this_index; $largest_value = $data; } } #do something with largest data