Hmm. I tried this test script:
#!/usr/bin/perl
use strict;
use warnings;
my %hash = map { $_ => 1 } (0..5);
my %copy = %hash;
my $hash_keys = join(' ', keys %hash);
my $copy_keys = join(' ', keys %copy);
print "$hash_keys --> $copy_keys, ",
$hash_keys eq $copy_keys ? "Same" : "Different",
" order \n";
with several different versions of Perl. It prints "Different order" with all the versions I tried (5.8.9, 5.10.1, 5.12.5, 5.14.4, 5.16.3, 5.17.10). With all but 5.17.10, the output is the same each time the program is run:
4 1 3 0 2 5 --> 1 4 0 3 2 5, Different order
With 5.17.10, I get different orders each time I run the program.
So, if I understand correctly, the code you posted is visibly broken and has been for a very long time.