my $type = ref( $e->{mealplans}->{mealplan} ); if ($type eq "ARRAY") { $mealplans=$e->{mealtypes}->{mealtype}; for my $mealtype ( @{$e->{mealtypes}->{mealtype}} ) { $rateid = $mealtype->{rateid}; print "$mealtype"; } }