#!/usr/bin/perl use strict; my $current = '/usr/local'; my $dir_start = '/home'; print "Current is '$current', starting with '$dir_start'\n\n"; recurse_directory( $dir_start ); print "\nDone.\n\n"; sub recurse_directory { ## variables my $current; my @local_list; ## get the dir we are in $current = $_[0]; ## get contents ## no "." or ".." dirs opendir( CURRENTDIR, "$current" ) or die "Can not open $current: $!"; @local_list = grep !/^\.\.?$/, readdir CURRENTDIR; closedir( CURRENTDIR ) or die "Can not close $current: $!"; ## now loop over the contents foreach my $x ( @local_list ) { my $file = $current . '/' . $x; recurse_directory( $file ) if ( $file -d ); print "$file\n"; } }