in reply to Regular expression parse pathname

Try this:
echo "/home/code/work" |\ perl -nle 'chomp; print $p .= $& while m{ \G (?: [^/]* /+ | [^/]+ \z ) + }xg'
The m/\G.../g match can be called several times, and each time it will start at the position where last time it left off.

However be aware, that this one-liner produces a little different tree than your example, but probably you want to represent the real file system tree and this result is a better representation of it.