package PreserveWD; use strict; use Cwd qw(cwd); sub new { my $class = shift; my $self = cwd; bless \$self, $class; } sub DESTROY { chdir ${+shift) or die "Cannot restore directory\n"; }