Rather than build the hash yourself, let perl do it for you. This returns counts of punctuation but is extremely easy to modify to return other classes of characters.

Update: added \p{Symbol} to filter regex.

use warnings; use strict; use charnames(); my %chars; while (my $line = <DATA>) { $chars{chop $line}++ while length $line; } for (keys %chars) { next unless /\p{Punct}|\p{Symbol}/; # Comment out or change this l +ine to suit my $char_count = sprintf "%25s %8s", (lc charnames::viacode(ord $_)), $chars{$_}; print "$char_count\n"; } __DATA__ Is a question that will probably seem absurd to those who are at all familiar with mineral springs or Saratoga waters. Nevertheless, it is a not unfrequent and amusing occur- rence to hear remarks from strangers and greenies who have a preconceived notion that the springs are doctored, and that a mixture of salts, etc., is tipped in every night or early in the morning! Strange that the art should be limited to the village of Saratoga! The incredulity of some people is the most ridiculous credulity known. Such wonders as the spouting springs, the "strongest" in Sara- toga, come from so small an orifice in the ground, as to preclude the least possibility of adulteration. Besides, the manufactured article would be too costly to allow such im- mense quantities to flow away unused. '{{{}}}]][[-0)(*&^^!@#$>>,<<>`~`' __END__
_____________________________________________________________
returns:
                    comma        9
           quotation mark        2
           less-than sign        2
        greater-than sign        3
        circumflex accent        2
                ampersand        1
         left parenthesis        1
             grave accent        2
              dollar sign        1
                 asterisk        1
                    tilde        1
             hyphen-minus        4
                full stop        5
      left square bracket        2
            commercial at        1
         exclamation mark        3
       left curly bracket        3
     right square bracket        2
              number sign        1
                 low line        4
        right parenthesis        1
               apostrophe        2
      right curly bracket        3

In reply to Re: punctuation search (different!) by thundergnat
in thread punctuation search (different!) by Yoda_Oz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.