use File::Find; @ARGV = (); find sub { push @ARGV, $File::Find::name if -f and /\.html$/; }, "."; { local $^I = ".bak"; local $/; while (<>) { if (s/foo/bar/g) { # changes? print; # print the new one } else { # no changes? back it out! close ARGVOUT; # for windows, not needed on Unix rename "$ARGV$^I", $ARGV or warn "Cannot rename for $ARGV$^I: $!"; } } }