#!perl use Test::More; my %storage; use constant SAMPLE_CONSTANT => defined eval { $storage{cache} = get_string('abcd') }; sub get_string { my ( $str ) = @_; return ":$str:"; } is SAMPLE_CONSTANT, 1, "constant is set to true"; is $storage{cache}, ':abcd:', "cache is set at compile time"; done_testing;