my @sorted=do{ my @keys=map func($unsrt[$_]) . ":$_", 0 .. $#unsrt; @unsrt[ map +(split /:/)[-1], sort @keys ]; };