#!/usr/bin/perl -w use strict; my %index = ( 'node' => 1, 'node-cat' => 2, 'node-cat-cat' => 3, 'node-cat-cat-cat' => 4, 'node-bat-bat-cat' => 4, 'node-cat-cat-cat-cat' => 5, 'node-cat-bat-bat-bat' => 5, 'node-cat-cat-bat-bat' => 2, ); my $key; my $test='node-cat-cat'; foreach $key (sort keys %index) { print "$key: $index{$key}\n"; } # # DELETE all child nodes. # print "\nDelete children of $test :\n"; foreach $key (%index){ #foreach $key (sort keys %index){ #while ($key = each %index) { delete $index{$key} if ($key =~ /$test.+/); } print "\nFinal Hash:\n"; foreach $key (sort keys %index) { print "$key: $index{$key}\n"; }