#!/usr/bin/perl use strict; use warnings; use Cwd 'abs_path'; my $somepath = "/var/log/../../home/poletti/../../etc/passwd"; print "starting path: [$somepath]\n"; print "abs_path : [", abs_path($somepath), "]\n" __END__ starting path: [/var/log/../../home/poletti/../../etc/passwd] abs_path : [/etc/passwd] #### abs_path my $abs_path = abs_path($file); Uses the same algorithm as getcwd(). Symbolic links and relative- path components ("." and "..") are resolved to return the canonical pathname, just like realpath(3).