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


in reply to How to alias a whole namespace to another namespace (in this case main::)

I had to do this some time back and ended up with this:

package as; sub import { my ($class,$caller) = ($_[1],caller); die "Mal-formed package name '$class'" unless $class =~ /^(?:\w|(? +<!^)(?<!:)::(?!\z))+\z/; die "Namespace already exists" if (keys %{"$class\::"}); *{"$class\::"} = \*{"$caller\::"}; ($class .= ".pm") =~ s!::!/!g; ($caller .= ".pm") =~ s!::!/!g; $INC{$class} = exists $INC{$caller} ? $INC{$caller}:$0; 1; } 1;

Update: Pfft, I went the wrong way. You're going to want to alias the main namespace to your target namespace as such:

# here we are in Utils.pm package main; use as "Utils"; package Utils; ...

The reason for this is that you cannot reassign the main:: namespace. This merely makes Utils point to main's namespace and anything declared in Utils is also being declared in main.