my (%hash, @G1_out, @G2_out, ...); $hash{$_}=\@G1_out for (qw (H0 ...)); $hash{$_}=\@G2_out for (qw (PX ...)); while (my $input = ) { chomp $input; my $prefix=substr($input, 0, 2); push @{$hash{$prefix}}, $input; }