in reply to String parsing

Tree::Builder might help:
use strict; use warnings; use Tree::Builder; use Data::Dumper; my @items = qw( Devices_CLI_Inspection Devices_CLI_Inspection_L2 Devices_CLI_Inspection_L2_FilterDatabase_General Devices_CLI_Inspection_L2_SpanningTree Devices_CLI_Inspection_L2_SpanningTree_MST Devices_CLI_Inspection_L2_VLAN_General Devices_CLI_Inspection_System_Config ); my $top = shift @items; my @items2 = @items; for (@items2) { s/^Devices_CLI_Inspection//; s{_}{/}g; } my $tb = Tree::Builder->new(); $tb->add($_) for @items2; my %hash=$tb->getTree(); print Dumper(\%hash); __END__ $VAR1 = { '' => { 'System' => { 'Config' => {} }, 'L2' => { 'VLAN' => { 'General' => {} }, 'SpanningTree' => { 'MST' => {} }, 'FilterDatabase' => { 'General' => {} } } } };