use Carp 'croak'; sub UNIVERSAL::AUTOLOAD { my($m) = $UNIVERSAL::AUTOLOAD =~ /::(\w+)$/; croak "Undefined subroutine &$UNIVERSAL::AUTOLOAD called" unless $m eq 'global'; print "this sub really is global\n"; } global(); { package foo; global(); } __output__ this sub really is global this sub really is global #### sub main::global { print "this isn't quite global\n"; } ::global(); { package foo; ::global(); } __output__ this isn't quite global this isn't quite global