#!/usr/bin/env perl -w use strict; use warnings 'all'; BEGIN { push @INC, sub { shift; my $classfile = shift; if( $classfile eq 'My/Missing/Module.pm' ) { (my $classname = $classfile) =~ s/\//::/g; $classname =~ s/\.pm$//; my $code = <<"CODE"; package $classname; sub hello { return qq{Hello, \@_!\\n}; }; 1; CODE # You have to return an open, readable filehandle: open my $ifh, '<', \$code; return $ifh; } else { return undef; }# end if() }; } # Load up a non-existant module: require My::Missing::Module; print My::Missing::Module::hello("Studly"); # Output: "Hello, Studly!"