use Tie::Scalar; { package Some::Class; our @ISA = qw(Tie::StdScalar); sub DESTROY { print "Object destroyed.\n"; } } if (1) { print "1\n"; # my $foo = 3; tie my $foo, 'Some::Class'; $foo = 3; print "2\n"; } print "3\n"; __END__ 1 2 Object destroyed. 3