use File::Spec::Unix (); sub remove_dot_dot { local $_ = $_[0]; $_ = File::Spec::Unix->canonpath($_); 1 while s#[^/]+/\.\./##g; s#/[^/]+/\.\.$#/#g; s#^[^/]+/\.\.$#.#g; return $_; }