package Coord; use overload '+' => \&add; sub new { my ($class, $x, $y) = @_; return bless { x => $x, y => $y}, $class; } sub add { my ($self, $other) = @_; return Coord->new($self->{x} + $other->{x}, $self->{y} + $other->{y}); }