package My::Class; use strict; use warnings; { # hide from the rest of the class my %CLASSDATA = ( foo => 1, bar => 2, baz => 3 ); # install generic accessor/mutator methods no strict 'refs'; for my $key(keys %CLASSDATA) { *$key = sub { shift; $CLASSDATA{$key} = shift if @_; return $CLASSDATA{$key}; }; } use strict 'refs'; }