use strict; use File::Find; use XML::LibXML; my ($file, $parser, $doc, $query, $node, $val, $tmtext); @ARGV=('.'); # search every file in this dir and all subdirs find (\&search, @ARGV); sub search{ $file=$_; if (grep -f && /\.xml$/i, $file){ $parser = XML::LibXML->new(); $doc = $parser->parse_file($file); $query = "//tm"; foreach $node ($doc->findnodes($query)){ $val = $node -> findvalue('@tmowner'); $tmtext = $node -> textContent(); # if we don't own the trademark, replace it with the text if ($val !~ /my_company/i){ ### REPLACE THE TM ELEMENT WITH THE TEXT CONTENT ### print " Replacing trademark element with $tmtext\n"; } } # foreach node } # if grep } # sub search