#!/usr/bin/perl use strict; use warnings; while () { my $pkg = do $_; print "Loaded package $pkg\n"; { no strict 'refs'; &{"${pkg}::spew"}(); } } #### package Foo; print "Executing foo.pl\n"; sub spew { print "This is package Foo\n"; } __PACKAGE__ #### Executing bar.pl Loaded package Bar This is package Bar Executing foo.pl Loaded package Foo This is package Foo