#!/usr/bin/perl use strict; use warnings; use File::Spec; my $somepath = "/var/log/../../home/poletti/../../etc/rc.d"; my @true; $somepath = "/../../../"; # Let's pretend $somepath is a directory... or is it? :) /^\.\./ ? pop( @true ) : push( @true, $_ ) foreach( File::Spec->splitdir($somepath) ); print File::Spec->catdir(@true), "\n";