sub lookup { my ($type, $ref) = @_; if ($type eq 'typeA') { return $ref->{key1}[3]{key2}; } elsif ($type eq 'typeB') { return $ref->{key3}; } elsif ($type eq 'typeC') { return $ref->[1]{key4}; } # ... }