in reply to Syntax error sorting hash keys

By the way, $a cmp $b is the default sort comparison, so you could have said just my @keys = sort keys %$hashref; or even bypassed using a @keys array by saying
for my $key (sort keys %$hashref) {
But including $a cmp $b doesn't slow anything down, since any of $a cmp $b, $b cmp $a, $a <=> $b, or $b <=> $a is optimized away and handled internally by the sort operation. Any other comparison block gets executed as real perl code, so is quite a bit slower.