package ProcessData; use strict; no strict "refs"; use Carp qw(croak); sub new { my ($pkg) = $_[0]; bless { _dispatch_table => {}, }, $pkg; } sub add_subroutine { if($_[1] && $_[2]) { if(ref($_[2]) eq "CODE") { ${$_[0]->{_dispatch_table}}{$_[1]} = $_[2]; } else { croak "The reference passed to add_subroutine() is not a CODE reference. "; } } else { croak "Insufficient arguments passed to add_subroutine(). "; } } sub process_data { if($_[1] && $_[2]) { #I've tried: ${$_[0]->{_dispatch_table}}{$_[1]}->($_[2]); #and tried ${${$_[0]->{_dispatch_table}}{$_[1]}}->($_[2]); #and some pretty odd other comibnations ... do stuff with the data ... } else { croak "Insufficient arguments passed to process_data(). "; } } sub process_locations { $_[0]->process_data("locations"); } test.pl use strict; use ProcessData; my $pd = ProcessData->new(); #Add references to the dispatch table. $pd->add_subroutine("dates", \&get_dates); $pd->add_subroutine("locations" \&get_locations); $pd->add_subroutine("contact_list", \&contact_list); $pd->process_locations;