use File::Spec::Functions qw/abs2rel/; my $path = "C:\\Dir1\\Dir2\\Dir3\\KeepMe"; my $base = "C:\\Dir1\\Dir2\\Dir3"; print abs2rel($path, $base), "\n"; # prints "KeepMe" # - or - use Path::Class qw/dir file/; my $path = dir('C:\\','Dir1','Dir2','Dir3','KeepMe'); my $base = dir('C:\\','Dir1','Dir2','Dir3'); print $path->relative($base), "\n"; # prints "KeepMe"