in reply to traverse DIR checking each level exists

use strict; use warnings; my @dirs = '/'; ### Starting directory my ($dir, $file, $path); while ($dir = shift(@dirs)) { opendir(DIR, $dir); while ($file = readdir(DIR)) { next if $file =~ /^\./; next if $file eq 'dir.pl'; ### Name of your script $path = $dir . $file; if (-d $path) { push (@dirs, "$path/"); next; } ### Do something with file path } }