I'm having a little trouble working out exactly what your problem is, given that your code is very badly formatted, but I suspect you want one of two things:
Use each to extract both key and value from the hash at the same time
Use Tie::IxHash to have your hash always return its keys/values in the same order they were entered.
Comment on Re: Hash accessing issue while returning hash from sub routinue