in reply to Command line works

The following example only covers the first half of your requirement and you'll probably get already got more direct answers since Perl evolved from the shell and they will probably be fine but there are advantages to doing it quite formally. This is how I do things like that now-

use strict; use Cwd "cwd"; use Path::Class (); use File::Spec (); my $dir = Path::Class::Dir->new( File::Spec->rel2abs( cwd() ) ); print "OH HAI, IZ IN $dir!\n"; my $target = eval { $dir->parent->parent } or die "Couldn't find the grandparent of '$dir': $@"; chdir($target) or die "Couldn't chdir($target)"; my $cwd = cwd(); print "OH HAI AGIN, IZ IN $cwd!\n";

It's more verbose and more complex (needs three modules) but it is (I think) more robust and leaves open many avenues and offers ancillary power-tools for working with dirs and files. It's also easier to debug and put in sensible tests.