Though you cannot sort a hash, but using the tie keyword and the Tie::IxHash module we can create a hash that keeps the keys ordered.

It is rarely used as it has a run-time penalty that usually is not worth the features, but if you really need this kind of behavior and if you are ready to pay the price, then go ahead. Use it.