value data else if(preg_match('/^.*\[(.*)\] => (.*)/',$line,$matches)) //store it in the current data array $cur_data[$matches[1]] = $matches[2]; //if this is the start of a print_r else if(trim($line) === '(') //create a new current data array $cur_data = array(); //if this is the end of a print_r else if(trim($line) === ')') { //store the current data array of key/value pairs $cur_packet['data'][] = $cur_data; } } } //store the last packet $all_packets[] = $cur_packet; //now you should be able to run something like: // //php parse.php > todiff && diff todiff $log_dir.catchall.txt // //in order to verify that your parser was correct foreach($all_packets as $packet) { echo $packet['origin'].PHP_EOL.PHP_EOL; foreach($packet['data'] as $data) print_r($data); echo PHP_EOL.PHP_EOL; }