package Test; sub new { my ($class, $foo, $bar) = @_; return bless { foo => $foo } => ref($class) || $class; } sub foo : lvalue { $_[0]->{foo} } package main; my $test = Test->new("foo"); print $test->foo, "\n"; $test->foo = "bar"; print $test->foo, "\n"; $test->foo =~ s/bar/baz/g; print $test->foo, "\n";