#!/bin/perl $delimiter = ","; $i=0; while(<>) { chomp; if ($_ =~ /^Subject:/){ @subject[$i] = $_; @subject[$i] =~ s/^Subject:(\D+)(\d+)/$2/e; } ... ... (more if statements to select what I need) ... (the concatenating part between the words "Out Comments" and "----") if ($_ =~ /^Lot Code/){ @lotCode[$i] = $_; @lotCode[$i]=~ s/^Lot Code(\s+)(\w+)/$2/e; $i++; } open OUTPUT, ">>data.txt"; # $allvar=join(',', $tag,$lotCode); # $result=$allvar; } for ($j=0; $j < $i; $j++) { print OUTPUT "@subject[$j];@failed[$j];@monthi[$j]/@dayi[$j]/@yeari[$j];@routerval[$j];" . "@tag[$j];@montho[$j]/@dayo[$j]/@yearo[$j];@lotCode[$j];@commentso[$j]\n"; print "@subject[$j];@failed[$j];@monthi[$j]/@dayi[$j]/@yeari[$j];@routerval[$j];" . "@tag[$j];@montho[$j]/@dayo[$j]/@yearo[$j];@lotCode[$j];@commentso[$j]\n"; }