my @color = qw(red blue black); use Tie::IxHash; tie my(%color), Tie::IxHash; # Existing colors: foreach(@color) { $color{$_}++; } # Attempt to add some: foreach(qw(purple blue green red)) { $color{$_}++ or print "Ooh, that's a new one: $_\n"; } print "I've got:\n"; print " * $_\n" foreach keys %color;