++wfsp. For uniformity, I would store *every* value of %gp as an arrayref, rather than need conditional logic on every use of a value.
Here is my quick refactor, with ++hbm's test data (padded to 5 columns):
use strict;
use warnings;
my %gp = (
G11 => [qw( Galpha-11 )],
G12 => [qw( Galpha-12 )],
G13 => [qw( Galpha-13 )],
G14 => [qw( Galpha-14 )],
G15 => [qw( Galpha-15 )],
G16 => [qw( Galpha-16 )],
Gs => [qw( Galpha-s )],
Gz => [qw( Galpha-z )],
Golf => [qw( Galpha-olf )],
Go => [qw( Galpha-o )],
Gq => [qw( Galpha-q )],
Gi => [qw( Galpha-i1 Galpha-i2 Galpha-i3 )],
Gt => [qw( Galpha-t1 Galpha-t2 Galpha-t3 )],
);
my $re = qr{
\A
( [^\t]* \t [^\t]* )
\t ( [^\t]* )
\t ( [^\t]* \t .* )
\z
}msx;
LINE:
while ( my $line = <DATA> ) {
chomp $line;
my ( $col_1_2, $col_3, $col_rest ) = ( $line =~ /$re/ ) or do {
warn "Line $. did not match: '$line'";
next LINE;
};
$col_3 =~ tr{ }{}d;
my $aref = $gp{$col_3} or do {
# No replacement needed? Is line still wanted?
warn "Did not find '$col_3' in %gp";
print $line, "\n";
next LINE;
};
for my $val ( @{ $aref } ) {
print join( "\t", $col_1_2, $val, $col_rest ), "\n";
}
}
__DATA__
biologist xargon Gi question col5
perl monks G11 answer? col5