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"; &{$self->{dispatch}{$command}}(); } sub new { my $class = shift; my $self = {}; bless $self, $class; $self->{dispatch} = { 'a'=> $self->can('first'), 'b'=> $self->can('second') }; return $self; } package ::; my $foo = new FOO(); $foo->dispatch('a'); $foo->dispatch('b'); #### $self->$command();