use File::Spec; print File::Spec->canonpath("foo/../bar/../baz/")."\n"; #### \baz