package foo; use warnings; use strict; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {@_}; bless($self, $class); $self->{file} = 'bar'; open my $handle, ">", $self->{file} || die "Cannot write to $self->{file}: $!\n"; print $handle "FooBar"; close $handle; return $self; } sub DESTROY { my $self = shift; print "In DESTROY()\n"; unlink $self->{file}; } 1; use warnings; use strict; $|++; my $f = foo->new(); print "Sleeping for 5 sec ... "; sleep(5); print "Done\n";