Trap 3 - a solution 

sub name_from_rgb {
  my $name;
  while(my($key, $value) = each %rgb) {
    $name = $key, last if $value eq $_[0];
  }
  keys %rgb;     # Reset the iterator
  return $name;
}