#!/usr/bin/perl use strict; use warnings; use lib sub { my $file=pop; return undef unless $file eq 'Foo/Bar.pm'; open my $fh, '<', \<<".EOM" or die $!; package Foo::Bar; use strict; use warnings; sub new { "Hello World!\n", "this is ", __PACKAGE__, "\n"; } 1; .EOM $fh; }; use Foo::Bar; print Foo::Bar->new; __END__