chdir $dir or die "Cannot change to $dir. $!";