if(ref($content->{'A'}) eq 'ARRAY'){ # this is an array so need the [0] in there $x=$content->{'A'}[0]{'R1'}{'T1'}{'S1'}, $y=$content->{'A'}[0]{'R1'}{'T1'}{'content'} . . # more dereferencing further along the tree }else{ # this is not an array $x=$content->{'A'}{'R1'}{'T1'}{'S1'}, $y=$content->{'A'}{'R1'}{'T1'}{'content'} . . # more dereferening further along the tree } #### $ifarray = "{'A'}[0]" else $ifarray = "{'A'}"