Thanks for everybody's great suggestions. Just to clear things up, there are no overlap between the groups. Each 2-digit combination can only appear in one group. Although, not every 2-digit combo will be represented. It would be helpful to handle these rogue entries.
It would be helpful to handle these rogue entries.
Well, then, to modify tommyw's code:
use strict;
my (%hash, @G1_out, @G2_out);
my @rogues;
$hash{$_}=\@G1_out for qw(H0 H1); # etc
$hash{$_}=\@G2_out for qw(PX P2);
while (<>) {
chomp;
push @{$hash{substr($_, 0, 2)} || \@rogues}, $_;
}