#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $foo = &splitme("foo/lol" => "blub","foo/lol/bla" => "grml"); print Dumper($foo); sub splitme { my %hash = @_; my $return; foreach my $element(keys %hash) { my @split=split(/\//,$element); my $last = { }; $return = $last; foreach my $i (0..$#split){ my $part = $split[$i]; if ($i == $#split){ $last->{$part} = $hash{$element}; }else{ $last->{$part} = { }; } $last = $last->{$part}; } } return $return; }