use strict; use warnings; use XML::Twig; use Data::Dumper; my $xmlStr = < Tue Sep 29 07:07:34 PDT 2009 a/b/hk/accts_subscription HKPwdPreReq a/b/hk/accts_forms HKPwdPreReq a/b/hk/custtradingpage BasicPrereq a/b/hk/accts_userinfo HKPwdPreReq a/b/hk/headermain a/b/hk/custservicepage a/b/hk/accts_transfermoney HKPwdPreReq a/b/hk/userprereq a/b/hk/indices_us a/b/hk/homeloggedmessage a/b/hk/lead a/b/hk/orderviewmin a/b/hk/accts_changelogin SessionPreReq XML my %urls; my $twig= new XML::Twig( twig_handlers => { 'appDeploymentFile' => \&appdep } ); $twig->parse($xmlStr); print Dumper(\%urls); exit; sub appdep { my ($t, $adep) = @_; my $name = $adep->att('name'); for my $urli ($adep->first_child('application')->children('urlInfo')) { $urls{ $urli->first_child('url')->text() } = $name; } } __END__ $VAR1 = { 'a/b/hk/accts_subscription' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/accts_changelogin' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/lead' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/orderviewmin' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/headermain' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/custservicepage' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/custtradingpage' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/accts_userinfo' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/accts_transfermoney' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/userprereq' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/homeloggedmessage' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/indices_us' => 'app-deployment.properties.hklcp.trading', 'a/b/hk/accts_forms' => 'app-deployment.properties.hklcp.trading' };