use XML::Rules; my $parser = XML::Rules->new( stripspaces => 3, rules => { 'ID,value' => 'content', field => sub {$_[1]->{ID} => $_[1]->{value}}, page => 'as array', root => sub {$_[1]->{page}}, } ); my $data = $parser->parse(\*DATA); use Data::Dumper; print Dumper($data); $data->[1]{Comments} = "many, of various quality"; # on the other hand the output is rather crazy. We have to convert the data structure to a format containing all the tags. print $parser->ToXML(root => {page => [map { my $fields = $_; +{field => [map { +{ID => [$_], value => [$fields->{$_}]} } keys %$fields]} } @$data]}, 0, ' '); # or, if I split it down a bit: print $parser->ToXML(root => {page => [map { hash2fields($_) } @$data]}, 0, ' '); sub hash2fields { my $fields = shift; return {field => [map { +{ID => [$_], value => [$fields->{$_}]} } keys %$fields]} } __DATA__ fname Jenda lname Krynicky Site PerlMonks Nick Jenda