use strict; use warnings; use XML::Twig; use Data::Dumper; my $xfile = < CHANNEL123 CATEGORY123 TopCategory This is TopCategory channel's Category This is TopCategory channel's Category 0 Vod;Download Channel456 cat456 TopCategory This is TopCategory channel's Category This is TopCategory channel's Category 0 Vod;Download chann678 cat678 TopCategory This is TopCategory channel's Category This is TopCategory channel's Category 0 Vod;Download EOF my %cats; my $t= new XML::Twig( twig_handlers => {cat => \&cat} ); $t->parse($xfile); sub cat { my ($twig, $cat) = @_; $cats{$cat->first_child('channelName')->text()} = $cat->first_child('name')->text(); } print Dumper(\%cats);