package SF; use strict; use warnings; use overload '.' => 'catSF'; sub new { my ($class, $str, $list) = @_; return bless {str => $str, list => $list}, $class; } sub catSF { my ($lhs, $rhs) = @_; $lhs = SF->new ("$lhs") if defined $lhs && ! ref $lhs; $rhs = SF->new ("$rhs") if defined $rhs && ! ref $rhs; $lhs = SF->new ("$lhs") if defined $lhs && ! $lhs->isa ('SF'); $rhs = SF->new ("$rhs") if defined $rhs && ! $rhs->isa ('SF'); return SF->new ("$lhs->{str}$rhs->{str}", $lhs->{list}, $rhs->{list}); } package main; my $name = SF->new ('GrandFather', [1, 2, 3]); my $catStr = "Name is $name"; print ref $catStr;