http://www.perlmonks.org?node_id=270145


in reply to Super Find critic needed

This comes to my mind:
  1. Why don't you do the replacements in NameReplace instead of pushing all filenames to a global array?
  2. I'd use
    s/\bservername(?:\.aa\.company(?:\.zzzz)?\.com)?\b/NEWNAME.\com/gi;
    in favour of your 3 replacements.
I don't know whether or not this will be more efficient (untested, incomplete code):
sub NameReplace { if( $_ =~ /\.(?:html?|cfm|cfml|cgi|js|pl)$/) { my $name = $File::Find::name; open ( F, $name ) || warn "$!: $name\n"; $data=join '',<F>; close (F); if ($data=~ s/\bservername(?:\.aa\.company(?:\.zzzz)?\.com)? +\b/NEWNAME.\com/gi) { if (open (F, ">$name")) { print F,$data; close(F); } else { warn "..." } } } }