your benefits http://blah.com/recognition/index.html http://blah.com/recognition/employee_service.html http://blah.com/recognition/awards.html Overridden Regional Content URL http://blah.com/equity_plans/incentive/override.html http://blah.com/index.html http://blah.com/comp/index.html http://blah.com/corp_policies/index.html http://blah.com/ero/index.html #### #!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; local $/; open(H,'subcontent2.xml') or die $!; my $wholefile =; close(H); my $xmlref = XMLin($wholefile, ForceArray=>['topic']); foreach(keys %{$xmlref->{'HEAD'}}){ if (!$xmlref->{HEAD}->{$_}->{Subcategories}->{category}){ print qq|GENERAL URL($_): | . $xmlref->{HEAD}->{$_}->{Url} . qq|\n|; } else { foreach my $cat($xmlref->{HEAD}->{$_}->{Subcategories}->{category}){ for (keys %$cat){ print qq|CATEGORY URL($_): | . $cat->{$_}->{Url} . qq|\n|; foreach my $topics ( values %{$cat->{$_}->{topics}}){ foreach(keys %{$topics}){ print qq|TOPIC URL($_): | . $topics->{$_}->{Url} . qq|\n|; } } } } } } #print Dumper $xmlref; 1; #### perl subcontent.pl GENERAL URL(Corporate Policies): http://blah.com/corp_policies/index.html GENERAL URL(Compensation): http://blah.com/comp/index.html GENERAL URL(Early Retirement): http://blah.com/ero/index.html CATEGORY URL(Employee Recognition): http://blah.com/recognition/index.html TOPIC URL(Employee Service Awards): http://blah.com/recognition/employee_service.html TOPIC URL(General Recognition and Performance-based Awards): http://blah.com/recognition/awards.html CATEGORY URL(Equity Plans): Overridden Regional Content URL TOPIC URL(Incentive Plan): http://blah.com/equity_plans/incentive/override.html