It is not generally true that each returns keys (or key/value pairs) in ascending order by key. It is true for some base classes that one can tie a hash to, but not for DB_File which is what the OP is asking about. See the description of each in Programing Perl 3rd Edition p. 703.