In addition to ikegami's wonderful advice, you should also be including use strict; and use warnings; to catch simple headaches. There's some reference material you may find valuable in perlref on callbacks (search term coderef). To store a code reference in a hash and call it, you can do the following:
my %hash = (code => sub{print 'x'});
&{$hash{code}};