use XML::Rules; my $updater = XML::Rules->new( style => 'filter', rules => { 'particular_tagname' => sub { my ($tag, $attr, $context) = @_; if (@$context == $that_depth_level and $attr->{this_atribute} eq 'some value' ) { do_stuff_to($attr); } return $tag => $attr; }, } ); $updater->filterfile( $infile, $outfile);