my $obj1 = new Obj;
my $obj2 = new Obj;
## The two objects above are now equal, let's say.
## Serialize them, then compare the serialized
## data.
use Storable qw/freeze/;
if (freeze($obj1) eq freeze($obj2)) {
## They're the same.
}
####
package Obj;
use Storable qw/freeze/;
use overload '==' => \&compare;
sub compare { return freeze($_[0]) eq freeze($_[1]) }
####
if ($obj1 == $obj2) {
# They're the same.
}