use strict; use warnings; my @stack = @ARGV; while (my $entry = shift @stack) { print $entry, "\n" and next if -f $entry; push @stack, glob("$entry/*"); }