#!/usr/bin/perl sub get_sub_dirs { my $dir = shift; opendir my $dh, $dir or die "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; closedir $dh; for my $file ( @files ) { print "$dir/$file\n"; get_sub_dirs( "$dir/$file" ) if -d "$dir/$file"; #notice the -d test, saying it found deeper subdirs } } $topdir= shift || '.'; get_sub_dirs($topdir); exit;