my $header; # Handle the first file separately so we can keep the "categories." my $file = shift; $header = "CATS \t$file"; # CATS is category column header. open my $fh, '<', $file or die "$file: $!"; my @lines = <$fh>; close $fh; chomp(@lines); for my $file (@ARGV) { # Add filename to header. $header .= "\t$file"; open my $fh, '<', $file or die "$file: $!"; # Iterate through file my $i = 0; while (my $line = <$fh>) { chomp $line; # Append tab and 2nd column to appropriate line. $lines[$i++] .= "\t" . (split /\t/, $line)[1]; } close $fh; } # print our header and each of our new lines. print $header, "\n"; print "$_\n" for @lines;