in reply to Regular expression parse pathname

The key is to accumulate your string as you loop through the directories. Not a one-liner, but this split solution gets the job done...
use strict; use warnings; my $s = '/home/code/work'; my @ds = split m{/}, $s; shift @ds; my $accum; for (@ds) { $accum .= "/$_"; print "$accum "; } print "\n";

Update: or, adapting your regex attempt:

my $s = '/home/code/work'; my $acc; while ($s =~ m#([^/]+)#g) { $acc .= "/$1"; print "$acc " }