#!/usr/bin/perl -w use strict; use Data::Dumper; use YAML; ... # from your code you do what was mentioned here: push @data, $tree; } # end of your foreach for my $record (@data) { my $cities = "$record->{'xml_api_reply'}{'weather'}{'forecast_information'}{'city'}->{'-data'}"; print "$cities\n"; }