use strict; my $BasePath = '\\DirA\DirB\DirC'; my $CurrentPath = '\\DirA\DirB\DirC\DirD\DirE'; $BasePath =~ s/\x5c/\x0d/g; $CurrentPath =~ s/\x5c/\x0d/g; $CurrentPath =~ s/$BasePath//; $CurrentPath =~ s/\x0d/\x5c/g; print "\n\$CurrentPath: ".$CurrentPath."\n";