package MyConstants; use strict; our $AUTOLOAD; sub import { my $package = shift; if ($_[0] eq 'AUTOLOAD') { my $caller = caller; no strict 'refs'; *{$caller.'::AUTOLOAD'} = \&{$package.'::AUTOLOAD'}; } } # Constants use constant { NIL => 0, FOO => 1, BAR => 2, }; sub AUTOLOAD { (my $func = $AUTOLOAD) =~ s/.*:://; no strict 'refs'; *{$AUTOLOAD} = \&{__PACKAGE__.$func}; goto &$func; } 1;