in reply to Setting a path for a sub function

I'm kind of confused. The code you gave should do exactly what you're wanting to do.
&scandir("c:/mydocu~1"); sub scandir { my $workdir = shift; # "c:/mydocu~1" is in $workdir chdir($workdir) || ... # chdir("c:/mydocu~1").. why not?
You may be interested in using warn or die instead of print when you're printing an error message (such as after your chdir).

Perhaps if you could elaborate on what problems you're having? You ask us how to do something and then show us how you're trying to do it, and that looks correct. I don't see what the problem is. If you're getting an error message, please pass that message along to us.