Yes. You can use an anonymous subroutine.
sub a {
my $xcode= sub { print "Hidden!\n"; };
$xcode->();
}
But "Is the best way to do this by just having a subroutine reference at the package level, and assigning anonymous subroutines into it from inside a() and b()?" sounds like a method which means you should probably be looking into using objects.
-Lee
"To be civilized is to deny one's nature."