$ perl -wle ' $path = "/foo/bar/foobar"; @elements = split m{/}, $path; print join "\n", @elements' foo bar foobar