sub my_context_sensitive { return $someobject but { method Str { # code for computing the string representation } method list { # code that's called in list context } ... } }