For instance: /about/ /about/me/ /about/you/ /about/me/myself/ would write a file in /about/ with me you a file in /you/ that is empty a file in /me/ with myself #### #!c:/Perl/perl/bin/perl.exe use strict; use warnings; use FileHandle; use File::Find qw(find); use File::Basename; use File::Copy; use File::Find; use Cwd; my $BaseDir = 'C:/Temp3/jcr_root/content/acs/'; find( \&createContentxml, $BaseDir ); sub createContentxml { if (-d $File::Find::name) { my $dir = $File::Find::name; # print $dir . ": \n"; &subdir($dir) ; } } sub subdir { my $dir2 = getcwd; print $dir2 . "\n"; my $dir = $_[0]; chdir($dir) or warn " not able to cd into $dir \n"; print "dir: $dir: \n"; opendir DH, $dir or die "Failed to open $dir: $!"; while ($_ = readdir(DH)) { next if $_ eq "." or $_ eq ".."; if (-d $_ ) { print $_ . "\n"; open (MYFILE, '>>test7.txt'); print MYFILE $_ . "\n"; close (MYFILE); } else { next; } } open (MYFILE, '>>empty.txt'); print MYFILE " empty \n"; close (MYFILE); chdir($dir2); return 0; # Did not find any subdirectory in this directory }