use strict; use warnings; use XML::Simple; my $xs = XML::Simple->new(ForceArray=>['httpd']); my $s = do { local $/=undef; }; my $conf = $xs->XMLin($s); my $ct = 0; foreach my $httpd ( @{$conf->{httpd}} ){ $ct++; if( ref($httpd) eq 'HASH' ){ $httpd->{number} = $ct; }else{ $httpd = { content=>$httpd, number=>$ct }; } } my $xml = $xs->XMLout($conf); print $xml; __DATA__