I'm not sure what you are after. But this tidy up of your code may contain the magic you require:

use warnings; use strict; my %people; my %families; while(<DATA>) { chomp; my ($family, $people) = split /=/, $_, 2; #split into two: family and memebers my @members = split /,\s*/, $people, -1; #split family lin +e into an array foreach my $member (@members) { #foreac +h member within array push @{$people{$member}}, $family; #push i +nto an array } push @{$families{$family}}, @members; } my $total_families = keys %families; my $total_people = 0; $total_people += @{$families{$_}} for keys %families; print "Num Families: $total_families\n"; print "Num People: $total_people\n"; print "All given Names: ", join (' ', sort keys %people), "\n"; print "All family names: ", join (' ', sort keys %families), "\n"; print "All names grouped by family:\n"; print " ", join ', ', do {my $famName = $_; map {"$_ $famName"} sort @{$families{$_}};}, + "\n" for sort keys %families; __DATA__ Flintstone=Barney, Fred, Wilma Jetson=Max, Tony, Wilma Simpson=Lisa, Barney, Wilma, Homer Alcatraz=Elijah, Max, Wilma

Prints:

Num Families: 4 Num People: 13 All given Names: Barney Elijah Fred Homer Lisa Max Tony Wilma All family names: Alcatraz Flintstone Jetson Simpson All names grouped by family: Elijah Alcatraz, Max Alcatraz, Wilma Alcatraz, Barney Flintstone, Fred Flintstone, Wilma Flintstone, Max Jetson, Tony Jetson, Wilma Jetson, Barney Simpson, Homer Simpson, Lisa Simpson, Wilma Simpson,

DWIM is Perl's answer to Gödel

In reply to Re: Calculating Total Different Array Terms On All Lines of Datafile by GrandFather
in thread Calculating Total Different Array Terms On All Lines of Datafile by sdslrn123

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.