use strict; use warnings; use Cwd qw(chdir getdcwd); show_drives(); system("dir/w"); chdir("D:/testdir") or die "Can't change to dir 'D:/testdir' ($!)\n"; system("dir/w"); sub show_drives { printf "You are in '%s' on the current drive\n", getdcwd(); printf "You are in '%s' on the 'D' drive\n", getdcwd('D'); print "\n"; }