Hashes do not record track insertion order, so you have to use a different data structure to do so. Tie::IxHash allows you to keep the same interface as a hash without actually being (just) a hash, but that's not necessary if you want something less magical.