I agree with other monks who have commented that the true inelegance may lie in other parts of the program, but I just wanted to point out that the condition sub-expression
[...] !(ref $array->[0] eq 'ARRAY') && ref $array->[0] eq 'HASH'
is redundant: if
$array->[0] is an array reference, it cannot be a hash reference; if it's a hash ref., it can't be an array ref.
A simpler, non-redundant condition expression would be:
ref $array eq 'ARRAY' && ref $array->[0] eq 'HASH'