ref new Foo or warn "example 1 is not an object\n"; ref new Foo->foo or warn "example 2 is not an object\n"; package Foo; sub new { bless {} } sub foo { "foo" }