use Cwd; sub TIESCALAR {bless {} => shift} sub FETCH {cwd} sub STORE {defined $_[1] and (chdir $_[1] or die $!)} our $cwd; tie $cwd => __PACKAGE__;