# All of the packages are Foo:: my $BASE_PACKAGE = "Foo"; $type_string = /^TYPE:\s*(.+)$/; # Type is used as the package name my $type = $1; my $sub = LoadPlugin($type, "process_line"); &{$sub}($arg1, $arg2, ...); sub LoadPlugin { my $package = shift(); my $routine = shift(); # construct Foo::$type my $plugin = $BASE_PACKAGE . "::" . $package; # try to load it eval "require $plugin"; if($@) { die "Couldn't load $plugin"; } # if we've loaded successfully return a # ref to the function my $sub = \&{$plugin . '::' . $routine}; return $sub; }