# # UNTESTED CODE # use File::Find; # If desired, change following to absolute path(s) to search my @directories = ('.'); find(\&search_and_replace, @directories); sub search_and_replace { # Item from search is a file -f && # Item's full name ends with '.shtml' $File::Find::name =~ m/\.shtml$/ && # Rename file so there is a backup rename($File::Find::name, $File::Find::name . '.bak'); # Read from original (now .bak), writing to target open(INF, $File::Find::name . '.bak') or die('Input: ', $!, "\n"); open(OUTF, '>' . $File::Find::name) or die('Output: ', $!, "\n"); { # Localize $_ to prevent potential problems with call local($_); # Loop thru file, doing replacements while ($line = ) { $line =~ s!(href="?)main\.page\?page=!$1/id=!g; print(OUTF $line); } } close(OUTF); close(INF); }