use Text::CSV; use warnings; use strict; # Reading the first file and extracting IVAL...S my $csv = Text::CSV->new; my @header = $csv->getline(\*DATA); $csv->column_names(@header); my $frst = $csv->getline_hr(\*DATA); my ($ivaldate, $ivalstart, $ivalend) = map { $frst->{$_} } qw( IVALDATE IVALSTART IVALEND ); # Reading all the rest my $line = ; $line =~ s/,/\t/g; print join "\t", qw( Date StartTime EndTime), $line; while ($line = ) { $line =~ s/,/\t/g; print join "\t", $ivaldate, $ivalstart, $ivalend, $line; } __DATA__ "CLLI","SWREL","RPTDATE","RPTIME","TZ","RPTTYPE","RPTPD","IVALDATE","IVALSTART","IVALEND","NUMENTIDS" "toroonxn0dw","EAGLE5 40.1.0-62.13.19","2009-11-13","19:00:23","EST ","STP SYSTEM TOTAL MEASUREMENTS ON TT","LAST","2009-11-13","18:45:00","19:00:00",256 "STATUS","TT","GTTPERFD","GTTUN0NS","GTTUN1NT","AGTTPERFD" "K","0",0,0,0,0 "K","1",0,0,0,0 "K","2",0,0,0,0 "K","3",0,0,0,0 "K","4",0,0,0,0 "K","5",0,0,0,0 "K","6",0,0,0,0 "K","7",0,0,0,0