# Could be wrapped in a BEGIN block if you wanted to foreach my $field (qw/ foo bar baz /) { *$field = sub { my $self = shift; $self->{$field} = shift if @_; $self->{$field}; }; }