# a unix/linux version: Traverse('./'); sub Traverse{ my $dir = shift; opendir my $dh, $dir or die "$!, for $dir"; for my $file ( grep !/^\./, readdir $dir ) { # but adjust for OS my $path = "$dir/$file"; if ( -d $path ) { Traverse( $path ); } else { ( $file =~ /\.txt$/ ) and Process( $path ); # or for VMS /\.TXT\;\d+$/ } } closedir $dh; } sub Process{ my $file = shift; open my $fh "<$file" or die "$!, for $file"; my @updated = (); while( <$fh> ) { s/find/replace/g; push @updated; } close $fh; open $fh, ">$file" or die "$!, for $file"; print $fh @updated; close $fh; }