#!/usr/bin/perl -i.bak -w # inplace.pl A short program to edit all the files in a dir inplace use strict; my $dir = 'c:/test1'; my @files; opendir(DIR, $dir) or die "Can't open dir $dir, Perl says $!\n"; while (my $file = readdir DIR) { # only push in the files not the dirs - use full path! push @files, "$dir/$file" unless -d "$dir/$file"; } closedir DIR; # now do an inplace edit. use a bare block and local to limit # the scope of our changes to the global @ARGV array to just here { local @ARGV = @files; # set up a temporary @ARGV for in-place edit while (<>) { s/this/that/; # modify the file print; # print the modifications } }