package MY::Constants; my %constants = ( FRED => 2, DINO => 4, WILMA => "bb-b-b-b-uck!", LARGE => 1e38, ); sub import { my $package = shift; for (@_) { unless (exists $constants{$_}) { require Carp; Carp::croak("Constant $_ invalid"); } { no strict 'refs'; my $full_name = caller()."::$_"; my $value = $constants{$_}; # for closure *$full_name = sub () { $value }; } } } '0 but true';