SP GC DC ID Descr GI Locus LF cat Ts All 5320 CGA1 1892 L2 3.1 dog Ts Sp 6420 beta 1 1849 L3 4.2 ------------------------------------ The format of the data is the same in the four files. #### #!/usr/bin/perl -w use strict; use warnings; my $infile1="file1.csv"; my $infile2="file2.csv"; my $infile3="file3.csv"; my $infile4="file4.csv"; open (my $in_fh1, "<", $infile1) or die "Can't open $infile1" ($!); open (my $in_fh2, "<", $infile2) or die "Can't open $infile2" ($!); open (my $in_fh3, "<", $infile3) or die "Can't open $infile3" ($!); open (my $in_fh4, "<", $infile4) or die "Can't open $infile4" ($!); open (my $out_fh, ">", "file1_4.csv"); while (defined(my $line1=<$in_fh1>) || defined (my $line2=<$in_fh2)|| defined (my $line3=<$in_fh3)|| defined (my $line4=<$in_fh4) ){ chomp $line1; $line1=~s/\t/,/g; my @columnheadings=split (/\t/, $line1); my $headings=join(",", @columnheadings); chomp $line2; $line2=~s/\t/,/g; chomp $line3; $line3=~s/\t/,/g; chomp $line4; $line4=~s/\t/,/g; print $out_fh "$headings\n"; }