#!/usr/bin/perl -w use Cwd qw/getcwd realpath/; use strict; my %processed; sub recursive { my $dirarg = shift; chdir $dirarg; my @results = map { chomp; realpath($_); } `ls $dirarg`; # ls is my example "vendor program" that returns files/dirs # prevent infinite recursion because of sym-links $processed{$dirarg} = 1; my @found = grep { -f } @results; # get list of files foreach my $dir ( grep { -d } @results ) { # same for directories push @found, recursive($dir) unless($processed{$dir}); } return @found; } sub queue { my @heap = ( shift ); my %processed = (); while(-d $heap[-1]) { my $dir = pop @heap; next if $processed{$dir}; chdir $dir; my @result = map { chomp; realpath($_); } `ls $dir`; $processed{$dir} = 1; unshift @heap, grep { -f } @result; push @heap, grep { -d } @result; } return @heap; } print join "\n", (recursive(getcwd()), "\n"); print join "\n", (queue(getcwd()), "\n");