#!/usr/bin/perl -w use strict; use XML::Twig; use YAML; my %hash; XML::Twig->new( twig_handlers => { elt => sub { $hash{$_->field('key')}= $_->field('value'); $_->insert_new_elt( first_child => ts => scalar localtime); $_[0]->flush; # flushes the doc to use less memory (might be overkill ;--) } }, pretty_print => 'record_c', ) ->parse( \*DATA) ->flush; # to flush the closing tag for doc print "\n\nHASH:\n", Dump \%hash; __DATA__ key1value1 key2value2 key3value3 key4value4