sub DESTROY { my $self = shift ; if ( $self->{out} && $self->{out}->opened() ) { ... do stuff .... close $self->{out} ; } }