Your object is based on a hash, as most objects and external modules do. So the same effects apply, including the return of key/value pairs in a pseudo random order. You have to readjust your expectations or use a different data model. This means abandoning use of XML::Twig.