# here $count and $private_func are undef # add_to_count() sub_from_count() get_count() set_count() and widget() # are the only ways to access $count and ($)private_func() { # use a closure to keep peoples sticky fingers off $count my $count; # define a func totally private to this closure my $private_func = sub { [blah blah blah] } # now here are a couple of modifiers sub add_to_count { ++$count } sub sub_from_count { --$count } # and the usual couple of accessors.... sub get_count { $count } sub set_count { my ($new_count, $user ) = @_; if ( $user = 'root' ) { # OK, OK so it is a silly example! $count = $new_count; return $count; } else { warn "Only root can set count directly, use add/sub/get blah..." return undef; } } # and something silly to use our private func... sub widget { &$private_func(@_) if $moon_in_venus && $believe_that_sort of stuff; } } # here $count and $private_func are undef