package ConstExporter; use warnings; use strict; my %CONSTANTS = ( foo => "abc", bar => "xyz", quz => "123", ); sub import { my ($class, @export) = @_; my ($callpack) = caller; for my $exp (@export) { die "bad constant name '$exp'" unless exists $CONSTANTS{$exp}; no strict 'refs'; *{"${callpack}::$exp"} = sub () { $CONSTANTS{$exp} }; } } 1;