#!/usr/bin/perl -w use Cwd; use strict; sub ScanTree { my $startdir = shift; # grab startdir as param passed to sub my $initdir = &cwd; # grab current working directory (see below) chdir( $startdir ) or die "Unable to enter $startdir: $!\n"; opendir( DIR, "." ) or die "Unable to open $startdir: $!\n"; my @names = readdir( DIR ) or die "Unable to read $startdir: $!\n"; close( DIR ); foreach my $name( @names ) { next if( $name eq "." ); next if( $name eq ".." ); if( -d $name ) { &ScanTree( $name ); next; } } # return user to saved current working directory (see above) chdir( $initdir ) or die "Unable to enter $initdir: $!\n"; } &ScanTree( "." );