in reply to Declaring my variables in sort function?

How "does it err" ?

Have you looked at the documentation for the sort function ? The variables $a and $b are magical for the sort function and you should not declare them as lexical variables using my. In fact, you should not name any of your own variables $a or $b.

As a general hint for receiving effective answers to your questions, see How (Not) To Ask A Question.