# in Plugin.pm: package Plugin; # the common base class sub new { my $type = shift; my $class = ref($type) || $type; return bless {}, $class; } # the public entry point, calls a private entry point in each derived class, _do_stuff(), to actually do the work sub do_stuff { my $self = shift; die 'Illegal plugin function' unless ($self->can('_do_stuff')); # polymorphic method call return $self->_do_stuff(); } # in Whatever.pm: package Whatever; use base qw( Plugin ); # subclass of Plugin sub new { my $type = shift; my $class = ref($type) || $type; return bless $class->SUPER::new, $class; } sub _do_stuff { # whatever this plugin does goes here } # etc. #### use Basename; for my $plugin_file ( ... ) { my $plugin_pkg = basename $pluginfile, '.pm'; eval { use $plugin_pkg; my $plugin_object = new $plugin_pkg; $plugin_object->do_stuff(); } if ($@) { # handle the error } }