use strict; use warnings; use 5.010; $| = 1; { package Dog; sub new { return bless {}; } sub bark { say 'Bow wow!' } sub DESTROY { print "destroy\n"; } } my $dog = Dog->new(); print 'hello', $dog->bark(), undef $dog, $dog->bark(), 'world', ; --output:-- Bow wow! Can't call method "bark" on an undefined value at 2.pl line 17. destroy