# let's suppose the list of services is the primary HoH structure: # -- top-level hash is keyed by service name # -- next-level hash is keyed by host name # -- $service{service_name}{host_name} = "command line"; my %service = ( servicea => { host1 => "/usr/local/bin/servicea -foo", host2 => "/usr/bin/servicea -bar", ... }, serviceb => { host2 => "/usr/bin/serviceb -baz", host3 => "/usr/local/bin/serviceb -boo" ... }, ... ); # now populate %host HoH to store the same information, but # with host names as top-level keys and service names as sub-keys: my %host; for my $srvc ( keys %service ) { for my $hst ( keys %{$service{$srvc}} ) { $host{$hst}{$srvc} = $service{$srvc}{$hst}; } } # to set up an option menu of services for a particular host, # use the %host hash: my $hostname = `hostname`; chomp $hostname; my @available_services = sort keys %{$host{$hostname}}; ... # to show which hosts are available to run a given service, # use the %service hash: my $servicename = ...; # assuming there's some service of interest my @available_hosts = sort keys %{$service{$servicename}};