#!/usr/bin/perl use strict; use warnings; my $perl_datastructure = { ... }; sub finder { my ($search,$p)= @_; return(@$p) if ($search eq '' and ref $p eq 'ARRAY'); return($p) if ($search eq ''); $p= $perl_datastructure if (not defined $p); if (ref $p eq 'HASH') { $search=~ s/^(.*?)(->|$)//; my $bit=$1; return finder($search,$p->{$bit}) if (exists $p->{$bit}); return(); } if (ref $p eq 'ARRAY') { my @results=(); foreach my $a ( @$p ) { push @results, finder($search,$a); } return @results; } #here should be error messages or further #code to handle refs and scalars } print join(' ',finder('Root->PersonA->Pets')),"\n"; print join (" ",finder('Root->PersonB->Pets')),"\n"; #### PetA PetB PetAA PetBB