use strict; use Scope::Guard; my $x; { my $g = Scope::Guard->new(sub {$x; warn "destroyed"}); } warn "end"; #### use strict; use Test::More tests=>2; use Scope::Guard; sub try { my @res; my @subs = do { my $g; ( sub { push @res, 'a'; $g = Scope::Guard->new( sub { warn "destroyed"; push @res, 'destroyed' } ); }, sub { push @res, 'b'; undef $g; } ); }; ( shift @subs )->(); is_deeply( \@res, ['a'] ); undef @subs; is_deeply( \@res, [ 'a', 'destroyed' ] ); } try();