#!/usr/bin/perl use warnings; use strict; use Data::Diver qw{ DiveRef }; use Data::Dumper; my $hash = {}; my @path; while () { chomp; s/^(\t*)//; my $depth = length $1; splice @path, $depth + 1; $path[$depth] = $_; DiveRef($hash, @path); } print Dumper $hash; __DATA__ one two three four five six