The example given suggests he wanted a stable sorting,
hence my "use sort 'stable'". Your code only gives a stable
sorting because that happens to be the default on 5.8.0,
but that may change in a future version of perl (and if
a sort happens to be stable in pre-5.8.0, it's just a coincidence).
But even in the one example given it's shown that keys
can appear multiple times. You don't have to assume that,
it's given. And as you notice, where duplicate keys appear
in the input, they appear in the same order in the output.
Hence the stability.