while () { if (/"X"/) { #The trash data has these 3 characters in it print TRASH "$_\n"; } else { #Now to deal with the data I want to keep if($csv->parse($_)) { #checks to see if data exists in $_ and parses it if it does my @fields=$csv->fields; # puts the values from each field in an array my $elements=@fields; #gets the number of elements in the array for ($x=0;$x<$elements;$x++) { print OUTFILE "$fields[$x]\t"; } } } }