@input |> map {[$_, &expensive_func($_)} |> sort { $a->[1] cmp $b->[1] } |> map {$_->[0]} |> my @output;