Ah, that's interesting, because when I tried something similar, I had $a within the lexical scope of the comparison function definition, which of course did not work:
c:\@Work\Perl\monks>perl -wMstrict -lE
"use warnings;
use strict;
;;
my $a = 1;
;;
sub numerically { $a <=> $b }
;;
my @arr = sort qw( 1 2 10 21 11 12 );
say qq{@arr};
;;
@arr = sort numerically @arr;
say qq{@arr};
"
1 10 11 12 2 21
1 2 11 21 10 12
I guess the take-away advice is that there should be a heavy application of
Don't Do That™ whenever one contemplates creating lexical versions of special, non-punctuation variables.
Give a man a fish: <%-(-(-(-<