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; #### #!/usr/bin/perl; use MyConstants qw(AUTOLOAD); use strict; use constant { NIL => -1 }; my @ary = qw(ene mene muh); print join(" => ", @ary[FOO(),NIL()]),$/; __END__ mene => muh