for my $field (qw(name race aliases)) { my $slot = __PACKAGE__ . "::$field"; no strict "refs"; # So symbolic ref to typeglob works *$field = sub { my $self = shift; $self->{$slot} = shift if @_; return $self->{$slot}; }; }