#!/usr/bin/perl -w use strict; use warnings; use XML::Twig; # keep_spaces is not completely necessary, it's just # there to keep the initial formating of the file my $twig= XML::Twig->new( keep_spaces => 1) ->parse( \*DATA) ; my $i=0; foreach my $httpd ( $twig->root->children( 'httpd')) { my $config= $httpd->text; # do something with $config $httpd->set_att( config => ++$i); } $twig->print; __DATA__