Some index utils in List:MoreUtils are useful;
use strict;
use warnings;
use List::MoreUtils qw(firstidx indexes);
use Data::Dump qw(pp);
my @matrix = (
[qw(t1 t1 t2 t2 t2)],
[qw(a1 a2 a1 a1 a2)],
[qw(intron intron UTR_CG UTR UTR)],
);
die "No UTR_CG column!" unless ( (firstidx {$_ eq 'UTR_CG'}@{$matrix[-
+1]}) > -1);
my @utr_cols = indexes { $_ eq 'UTR' } @{$matrix[-1]};
die "Must have 2 or more UTR columns!" unless (@utr_cols >= 2);
shift @utr_cols; #save first seen UTR column
delete @{$matrix[$_]}[@utr_cols] for (0..@matrix-1);
pp \@matrix;
__END__
[
["t1", "t1", "t2", "t2"],
["a1", "a2", "a1", "a1"],
["intron", "intron", "UTR_CG", "UTR"],
]