use File::Spec; .. my $current_dir = File::Spec->rel2abs('.'); .. #in the sub now you can do: my $path_to_go = File::Spec->catdir( $current_dir , $current_corner ); chdir $path_to_go or die "unable to chdir in $path_to_go\n";