my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } # or <=>, or $b before $a map { [$_, f($_)] } @unsorted;