use overload '""' => \&as_string; sub as_string { my $self = shift; ... }