foreach (@animals) { $animals{$_}++; } # initialize %animals hash #### @animals{@animals} = (1) x @animals;