while( <> ) { chomp; my( $key, $subkey ) = split; $h{$key}{$subkey}++; } #### #! /usr/bin/perl -w use strict; my %h; # two different subkeys $h{foo}{bar}++; $h{foo}{rat}++; # one subkey $h{fob}{rat}++; # one subkey seen more than once $h{fod}{car}++; $h{fod}{car}++; for my $c( keys %h ) { if( scalar keys %{$h{$c}} == 1 and $h{$c}{(keys %{$h{$c}})[0]} == 1 ) { print "$c has a ${\(keys %{$h{$c}})[0]}\n"; } else { print "$c is complicated\n"; } }