Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

is there a way to conditionally execute a subroutine defined as hash value?
In the example below I get both subroutines executed, while I'd like to only execute one of them based on the value of $test.

use strict; my $calls = { A => \&print_A(), B => \&print_B(), }; my $test = 'A'; $calls->{$test}; sub print_A { print "\nA\n"; } sub print_B { print "\nB\n"; }