#!/usr/bin/perl use warnings; use strict; use File::Find::Rule; #find all html files in specified directory my $dir = "/var/www/site/htdocs/"; my $rule = File::Find::Rule->file->name("*.html")->start( $dir ); #keep track of the changed files in a file open(OUTFILE,">>fixed_files.txt") || die "cant open fixed_files.txt, $!\n"; while ( my $html_file = $rule->match ) { rename($html_file, "$html_file.bak") or die; open(my $fh_in, '<', "$html_file.bak") or die; open(my $fh_out, '>', $html_file) or die; while (<$fh_in>) { #add the urchin code if (s||\n|i) { print OUTFILE "$html_file: fixed Urchin code\n"; } print $fh_out $_; } close($fh_in); close($fh_out); } close OUTFILE;