package StringObject; use strict; use warnings; use overload q{""} => \&to_string; sub new { my ($class, $string) = @_; return bless \$string, $class; } sub s { my ($self, $match, $substitute) = @_; $$self =~ s/$match/$substitute/; return $self; } sub to_string { my ($self) = @_; return $$self; } 1;