$U = "a"; $V = 1; $W = $U.$V; @things=<$folder_to_populate_from/*>; foreach $thing (@things){ if(-f $thing){push(@FILES,$thing)} if(-d $thing){ push(@DIRS,$thing); @dir=<$thing/*>; push(@$W,@dir); } } &cycle; sub cycle{ foreach $thing (@$W){ if(-f $thing){push(@FILES,$thing)} if(-d $thing){ push(@DIRS,$thing); @dir=<$thing/*>; push(@X,@dir); } } if($#X > -1){++$V;$W = $U.$V;@$W=@X;@X=();&cycle} }#cycle 1;