my %commands = ( command1 => { description => "Does something", function => sub { my $var = shift; print "var = $var\n"} }, ) my $cmd = 'command1'; $commands{$cmd}{function}($param) #### my $func = \&version1; is($func($param), 0, 'makes sense'); my $func = \&version2; is($func($param), 0, 'does it ?'); sub version1{[some code]} sub version2{[some code]}