my $class = ref($class) || $class; #### my $foo = Foo->new(); my $foo2 = $foo->new(); my $foo3 = Foo::new(); #### +------+-------+-------+ | true | false | final | +------+-------+-------+ | 0 | 0 | 0 | Foo::new() +------+-------+-------+ | 0 | 1 | 1 | Foo->new() +------+-------+-------+ | 1 | x | 1 | $foo->new() +------+-------+-------+ #### package Foo; sub new { my ($class) = @_; $class = ref($class) || $class; return bless {}, $class; } sub test { print "Test" } package main; my $foo = Foo::new(); print $foo; $foo->test(); #### main=HASH(0x180035c) #### Can't locate object method "test" via package "main" at test.pl line 14. #### eval { Foo::new() }; ok(!$@, "Foo::new dies when called as a function");