Code Used: my $t = new XML::Twig( twig_handlers => { "content"=>\&process_root }, pretty_print =>'nice', )->parsefile("$ARGV[0]"); my $say=$t->sprint; print FOUT "$say"; sub process_root { my ($a,$b,$c)=@_; my $bchild; for $bchild ($b->children) { if ($bchild->tag eq 'dl') { $bchild=&dl($a,$bchild); } } return $b; } sub dl { my ($a,$b,$c)=@_; my $bchild; if ($bchild->text) { $bchild->subs_text( qr{(.+?)\t(.+?)\n},'&elt(first=>{},$1)&elt(second=>{},$2)'); } return $b; }