use ThisModule qw(foo); #### { my $value = undef; sub foo { unless (defined $value) { # initialize $value here } # do foo stuff using $value here } }