overload::StrVal($var)
Update: I figured that'd be XS code and so wouldn't trigger DB::sub, but it is actually this rather simple Perl code (from overload.pm):
sub AddrRef {
my $package = ref $_[0];
return "$_[0]" unless $package;
require Scalar::Util;
my $class = Scalar::Util::blessed($_[0]);
my $class_prefix = defined($class) ? "$class=" : "";
my $type = Scalar::Util::reftype($_[0]);
my $addr = Scalar::Util::refaddr($_[0]);
return sprintf("$class_prefix$type(0x%x)", $addr);
}
So you can just use that same technique yourself. Yes, reftype() and refaddr() are XS unless Scalar::Util fails to load its XS component, in which case it uses the Perl replacements found in Util.pm, which you could also copy (they rebless to avoid overload magic).