For one, you can't use chained comparisons until Perl 6. Instead, you have to do this:
if (55 < $age && $age <= 60) ...
When dealing with ranges, if they are predictable intervals, you can do math and end up with something like this:
foreach (keys %insitution_table) { $institution_table{$_}{ages}[$age/5]++; }
This builds an array of 5-year grouped ages. Consider how difficult it would be to iterate through a listing which uses text names for ranges. "fifty" comes before "forty" in the alphabet, and "twenty" comes after. If you need to know who's in the 50-55 age group:
my $sample = $insitution_table{$_}{ages}[60/5];
As for your initial block, you're using regular expressions when you could be using something much simpler:
my %valid_institutions = map { $_ => $_ } ( $hospital1, $hospital2, ); # ... my $key = $institution && ($valid_institution{lc($institution)} || "other") || "unaffiliated"; $institution_table{$key}{count}++;
This sets $key to be the appropriate spot to insert. You can add new types to the list and no new code is required. If there's one thing that really irritating, it's these endless chained "if" statements that do very little but take up a ton of room. Sure, if you get paid per line of code, you might have a case, but still. It looks like it escaped from some long forgotten COBOL code if you ask me.

Also, I've put 'count' at the end because you were using the hash in an invalid way, something you would notice with use strict; Note that you were putting a number into, for example, $institution_table{$foo} and then later using this number as a hash when you do this: $institution_table{$foo}{bar}++

Update:
By request, here's a quick explanation about what the map was doing. I've used it here to turn a list of variables into a hash, so that later, it is very easy to see if another variable is in this original list. Typically, this is done like this:
my %foo = map { $_ => 1 } qw[ foo bar baz ]; my $foo = 'foo'; print "\$foo is in the list\n" if ($foo{$foo});
However, since in this case the output value of the hash was going to be used for something else, I just assigned it to the same value. This way the code looks like this:
... $valid_institution{lc($institution)} || ...
Instead of:
... $valid_institution{lc($institution)} && lc($institution) ||  ...

In reply to Re: an easier way with grep, map, and/or sort? by tadman
in thread an easier way with grep, map, and/or sort? by aufrank

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.