#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my @content = (); my $no_of_seq = scalar(@content); my @myArray; for my $row (@content) { my @columns = split ' ', $row; push @myArray, \@columns; } say join "\t", $myArray[0][0], 'sum'; my $width = $#{ $myArray[0] }; for (my $row = 1; $row < $no_of_seq; $row++){ print $myArray[$row][0], "\t"; my $sum = 0; for my $col (@{ $myArray[$row] }[1 .. $width]) { $sum += $col; } say $sum; } __DATA__ GeneID Tp1 Tp2 Tp3 ALA1 10 12 11 THR8 57 99 12 HUA4 100 177 199 ABA5 2 5 10 #### #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use List::Util qw{ sum }; ; # ignore the first line; say "GeneID\tSum"; while () { my @cols = split ' '; my $sum = sum(@cols[1 .. $#cols]); say join "\t", $cols[0], $sum; }