#!/usr/bin/perl -w use strict; my $dirname="/path/to/the/directory"; opendir(DIR,$dirname) or die "$dirname:$!"; while (my $entry=readdir(DIR)){ next if $entry eq '.'; next if $entry eq '..'; next if -d $entry; # see notes below | do something with this... } exit(0); #### #!/usr/bin/perl -w use strict; workTheDirectory("/path/to/the/directory"); exit(0); # # sub workTheDirectory { my $dirname=shift; opendir(DIR,$dirname) or die "$dirname:$!"; while (my $entry=readdir(DIR)){ next if $entry eq '.'; next if $entry eq '..'; if ( -d $entry ) { my $newdir = $dirname . "/" . $entry; #grow the path workTheDirectory($newdir); } | This is a file... | work it. } return; }