Does this do what you want?
#!perl use strict; # First, group them by the first part of the numeric field # and the other two columns # then find how much of the rest of the numeric field is needed # to distinguish the variations in the third column my %grouping; while(<DATA>) { my ($n, $n2, $c2, $c3) = /(\d+)\.(\S+)\s+(\w+)\s+(\w+)/; $grouping{$n}{$c2}{$c3}{$n2} = $_; } for my $n (sort {$a <=> $b} keys %grouping) { my $N = $grouping{$n}; for my $c2 (sort keys %$N) { my $C2 = $N->{$c2}; if (keys %$C2 > 1) { # print "$n$c2 is a complex group, containing:\n"; for my $c3 (sort keys %$C2) { my $C3 = $C2->{$c3}; # print "..(for c3=$c3):\n"; for my $n (sort keys %$C3) { print "$C3->{$n}"; } } } else { print "$n$c2 contains:\n"; my $C3 = $C2->{(keys %$C2)[0]}; for my $n (sort keys %$C3) { print " $C3->{$n}"; } } } } __DATA__ 0024.118.3A FT TFF 0024.118.3B FT TFF 0024.118.3C FT TFF 0024.118.3D FT TFF 0024.118.4 FF TFF 0039.04 NN OTH 0039.205.2 FT OTH 0039.205.6 FT TFF 409.176.12A FT TFF 409.176.12B FT TFF 409.176.12C FT TFF 409.176.12D FT OTH 409.176.12E FT OTH

Caution: Contents may have been coded under pressure.

In reply to Re: Creating Minimal Subgroups in a List of Characters by Roy Johnson
in thread Creating Minimal Subgroups in a List of Characters by periapt

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.