#! /usr/bin/perl -I. use strict; use warnings; use 5.010.000; my @dispatch = ( { file => 'x5-1.pl', subroutine => 'foo', # string here, not coderef } ); sub foo { say "wrong sub"; } for my $ref ( @dispatch ) { package MyModule; # declare package to contain imported functions require $ref->{file}; # import function(s) eval $ref->{subroutine}."('a')"; # call function with string-eval; remember to insert error handling # We are inside package MyModule, so no need for package name in string } say "At the end:"; # just a check what happens now with main::foo foo( 'b' ); say "Last Test:"; # and a final test MyModule::foo( 'c' );