sub first { print "This is first\n"; } sub second { print "This is second\n"; } sub dispatch { no strict 'refs'; my $command = shift; print "In dispatch, command = $command\n"; my %dispatch = ( 'a'=>'first', 'b'=>'second' ); &{$dispatch{$command}}(); } dispatch('a'); dispatch('b'); #### package FOO; sub first { print "This is first\n"; } sub second { print "This is second\n"; } sub dispatch { my $self = shift; no strict 'refs'; my $command = shift; print "In dispatch, command = $command\n"; my %dispatch = ( 'a'=>'first', 'b'=>'second' ); &{$self->{$dispatch{$command}}}(); } sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } package ::; my $foo = new FOO(); $foo->dispatch('a'); $foo->dispatch('b');