http://www.perlmonks.org?node_id=998913


in reply to Re^4: Correct syntax for using $INC to keep modules in same file
in thread can't import using exporter

Something like this:

package mem; sub import { my (undef, $package) = @_; $package =~ s!::!/!g; $INC{$package . '.pm'} = 1; }

As long as that appears logically before any use mem 'foo'; statements in your program, everything should work correctly. It's slightly more typing than your implementation of mem, but it keeps all of the details of the implementation in one place.