#! /usr/bin/perl use strict; use warnings; use Data::Dumper; my $categories = [ ['Telekommunikation', ['Festnetz', ['Telefon', ['Foo', 'Bar'] ], ['Telefax', ['Foo', 'Bar'] ], ], ['Mobilnetz', ['Handy used', ['Siemens', ['C25', 'C35', 'Other'] ], ['Nokia', ['5130', '7710', '8810', 'Other'] ], ['Panasonic', ['GD90', 'GD91', 'GD92'] ] ], ['Handy unused', ['Panasonic', ['GD90', 'GD91', 'GD92'] ], ['Siemens', ['C25', 'C35', 'Other'] ], ['Nokia', ['5130', '7710', '8810', 'Other'] ] ] ] ], ]; my $hashref = getPosition($categories,"",""); print Dumper($hashref); sub getPosition{ my ($arrayref,$title,$position) = @_; my @array = @{$arrayref}; my %hash = (); my $ref2hash = (); foreach my $index(0..(scalar(@array) - 1)){ my $type = ref($array[$index]); if($type eq 'ARRAY'){ $position .= '_'.$index; $ref2hash = getPosition($array[$index],$title,$position); %hash = (%hash,%{$ref2hash}); }# elsif unless($type){ $title = $title.'_'.$array[$index]; my $pos = $position.'_'.$index; $title =~ s/^_//; $pos =~ s/^_//; $hash{$title} = $pos; }# if }# foreach return \%hash; }# end getPosition