open (DIFFR, "javaex.log"); while () { $line=$_; #read first line if ($line =~ /at / || $line =~ /xception/) { chomp $line; print LOGFILE "$line,\n"; } }