I want to check if two references point to the same object. It seems I can simply use
if ($ref1 == $ref2) { # cheap numeric compare of references print \"ref
The function you are looking for is refaddr from Scalar::Util (after ensuring that the values being compared really are references):
use Scalar::Util 'refaddr'; if ($obj1 and ref($obj1) and $obj2 and ref($obj2) and refaddr($obj1) == refaddr($obj2)) { # objects are the same... }