print $b = $a;
It isn't immediately obvious to me what you expect this statement to do. What it actually does is to extract the value from $a, store it in $b and then print it. What did you intend?
Other things you might be interested to know:
- while takes a logical expression to evaluate and you have not given it one.
- $a and $b are not good choices for variable names especially when using sort.
- The ordering of keys within hashes is not a trivial thing.
- You never need double brackets around one expression in Perl.
It might be better all round for you to provide your expected output because it's not at all clear to me what your code is intended to do.