in reply to question on declaring variables
Yes, the declaration is the same for both files, but $a is a special variable, whereas $x and $y are not. You get the error messages because you correctly use strict:
Because of their special use by sort(), the variables $a and $b are exempted from this check.You should avoid using $a and $b because they are special for the sort function. As the helpful message reports, you need to declare x and y with my.
In Section
Seekers of Perl Wisdom