in reply to storing domain info in hashes of hashes

Try this:
use Data::Dumper; use strict; sub insert { my $domain_hash = shift; my @domain_chain = @_; my $parent = $domain_hash; my $cur_node; while ($cur_node = shift @domain_chain) { if (exists($parent->{$cur_node})) { $parent = $parent->{$cur_node}; } else { do { $parent->{$cur_node} = {}; $parent = $parent->{$cur_node}; } until (!($cur_node = shift @domain_chain)); } } } my $domain_hash = {}; insert($domain_hash, "www", "perlmonks", "com"); insert($domain_hash, "www", "perlmonks", "org"); insert($domain_hash, "www", "google", "com"); print Dumper($domain_hash);