use File::Spec::Functions qw(catdir catpath splitdir splitpath); my ($volume, $directories, $file) = splitpath '//special/semantic//path/definition'; my @dir = splitdir $directories; my $dir1 = catdir @dir; # '/special/semantic/path' my $dir2 = join '/', @dir; # '//special/semantic//path/' my $path1 = catpath $volume, $dir1, $file; # '/special/semantic/path/definition' my $path2 = catpath $volume, $dir2, $file; # '//special/semantic//path/definition'