optimize reg exp or code

[email protected] (allan juul) Wed, 18 Jun 2003 21:31:21 +0200
Newsgroups perl.macperl.anyperl
Message-ID <[email protected]>
hi

i have to search & replace about a dozen different words in 100000+ files. 

my approach was like this

my @wordlist = qw (word1 word2 etc word12);

...open files...

while (<FILE>) {
  s/<(word1|word2|etc|word12)>/<newword="$1"/g;
  s/</(word1|word2|etc|word12)>/</<newword>/g;
  print NEWFILE;
}


this works fine but is very very slow am sure because of the alternation in the 
reg exp.

so my second approach looks like:

while (<FILE>) {
  foreach my $tag (@wordlist) {
    s/<($tag)>/<newword="$1"/g;
    s/</$tag>/</<newword>/g;
  }
  print NEWFILE;
}

this doesnt work as intended since the second substitution seem to mess up the 
$1.

anyway, does anyone have a better/faster approach ?

thanks
./allan