in reply to recursive dir and file

First - you're reusing a global variable DIR. Either localise it before the opendir, or closedir it before the foreach.

Second, the problem with readdir is that you've lost your context. You probably need to do a chdir before you opendir so that when you're looking at $name, you'll be looking at it relative to the requested directory. That's the easy way, although it changes your current working directory for the rest of the script. And you'll need to chdir back after the recursive call to recurse_dir($name).

Or, you could just use File::Find and get all this done for you. Way easier. ;-)

sub recurse_dir { require File::Find; File::Find::find(sub { if (-f $File::Find::name and $File::Find::name =~ /\.sas$/) { chmod 0644, $File::Find::name; print "$File::Find::name has been changed\n"; } }, @_); }

(I also took the liberty of achoring your .sas test, and of using perl's built-in chmod function.)