#! /usr/bin/perl -w package MyPack; use strict; sub new { return bless {},__PACKAGE__; } sub DESTROY { print "I'm destroyed\n"; } print "[$]]\n\n"; if( 1 ){ my $obj = MyPack->new(); print "Inside the IF (1)\n"; } print "Outside the IF (1)\n"; print "\n"; if( defined(my $obj = MyPack->new() ) ){ print "Inside the IF (2)\n"; undef $obj; } print "Outside the IF (2)\n"; print "\n"; if( defined(my $obj = MyPack->new() ) ){ print "Inside the IF (3)\n"; } print "Outside the IF (3)\n"; #### [5.006] Inside the IF (1) I'm destroyed Outside the IF (1) Inside the IF (2) I'm destroyed Outside the IF (2) Inside the IF (3) Outside the IF (3) I'm destroyed