in reply to Help to handle subroutine

You should study the definition of a hash. Duplicate keys are not allowed. Tru using Data::Dumper on your input %xhash.