open ERROR, ">>$exceptionoutput" or $log->logdie ("Error opening $exceptionoutput file\n"); # Print the headings for the CSV file while(ERROR){ if($_ !~/STATUS CODE([0-9A-Za-z].*)VIP CODE/){ printf ERROR "STATUS CODE,TIMESTAMP,USERID,TRANSACTION TYPE,POLICY NUMBER,CREATION TYPE,VIP CODE\n"; last; } } close ERROR;