foreach my $file (@dirlisting) { ... DIR: foreach my $dfile (@ddir) { ... if (-d $dpath) { ... push @dirlisting,$dpath; ... } ... } ... }