open (DIFFR, "/tmp/log.diff"); while () { $line=$_; #read first line chomp($line); if ($line =~ /ERROR/) { print CSVFILE "$line,"; }