my @textsplit= split /\./, $text; my $p= pop @textsplit; foreach (reverse @textsplit) { my $new->{$_}= $p; $p= $new; }