my @dirs = 'Startdir'; while ( @dirs ) { my $current = shift @dirs; opendir my $dirh, $current or die $!; while( ... ) { # wie bei Dir im Programm # . und .. ausschließen if ( -d "$current/$entry" ) { push @dirs, "$current/$entry"; } } closedir $dirh; }