sub getdir { my $dir = shift; # Open the directory handle, reporting the reason ($!) opendir (my $dh, $dir) || die qq(Cannot opendir: $dir: $!); while( my $file = readdir($dh)) { next if ($file =~ m[^\.{1,2}$]); # Ignore . and .. my $path = $dir .'/'. $file; if (-e $path) { # do some stuff } elsif (-d $path) { getdir($path); } closedir ($dh); # Close the directory handle - OOPS } }