#!/usr/bin/perl -w use strict; package MyCwd; use Cwd; sub cd { warn "must assign to something!\n" if !defined(wantarray); my $class = shift; my $new_dir = shift; my $self = cwd; chdir $new_dir; bless(\$self, $class); } sub DESTROY { my $self = shift; chdir $$self; } "that's it!";