sub foo { my $self = shift; # oops, forgot this line before if (@_) { $self->{foo} = shift; return $self; } return $self->{foo}; }