use strict; use File::Find; my $root_dir = '/temp'; find(\&wanted, $root_dir); sub wanted { if ( -d ) { # you've been 'chdir'ed to this directory print "Directory: $_\n"; } else { # not a directory. do as you will } }