my (%history, $histcount); .... # get a new value here and only add it if its not there. $history{ $newvalue } = $histcount++ unless exists $history{ $newvalue };