package Foo; use overload '0+' => \&as_num; sub new { my $class = shift; my $self = { value => shift }; bless $self, $class; } sub as_num { my $self = shift; return $self->{value}; } package main; my $x = new Foo(3); my $z = (0+$x); # $x+0 also produces error