in reply to A problem with using the split command

Change the line to read:

foreach my $pwd (split(/\\/,'\foo\foo1\foo2')) { ...
and it should work correctly.

Update: The following code (as per above, but with an output):

foreach my $pwd (split(/\\/,'\foo\foo1\foo2')) { print $pwd, "\n"; }
produces the following output.
__OUTPUT__ foo foo1 foo2
Notice the extra blank line at the beginning? This occurs because of the initial leading slash in the string to split. You'll likely want to take that into concideration.