$path='./anything/../.../something'; #example $path=~s!/+!/!g; #replace //// by single / $path=~s!^\./!!; #remove starting ./ $path=~s!/\.(?=$|/)!!g; #remove all /. 1 while $path =~ s!/([^/]{3,}|[^/.][^/]*|\.[^/.])/\.\.(?=/|$)!!g; #remove /something/.. $path=~s!^([^/]{3,}|[^/.][^/]*|\.[^/.])/\.\./!!; #remove starting something/../ $path='.' if $path eq ''; #point current path if finally it is empty #at this place $path is normalized