sub fortunecookie { my $cookie = ...; if( ! $cookie ){ my $errstr = "failed to get a cookie because ..."; return bless \$errstr => 'YouveGotError' } return \$cookie } # ok a bit awkward with the stringref but it demonstrates that one can do this with scalars too