use File::Spec; foreach my $str ( File::Spec->splitdir( "/a///b/" ) ) { print "- \"$str\"\n"; } #### - "" - "a" - "" - "" - "b" - ""