in reply to Yet another problem with recursive code

Two words: deep recursion. Check this out:
sub scandir { my ($workdir) = &scandir; ...
The very first thing you do inside your 'scandir' sub is call it again. This is probably not what you want.