$re = '/(TEST_CASE_NAME.*?:(.*?)\n.*?PRIORITY.*?:(?!P3)(\w\d).*?=cut)/s';
$str = '=head2 Gen_001
TEST_CASE_NAME :GEN_001
PRIORITY :P0
RELEASE_INTRODUCED :7.4 AUTOMATED :YES
STEP_NAME : step1
STEP_DESC :Example desc for understanding STEP_RESULT :Example result for understanding
=cut
=head2 Gen_003
TEST_CASE_NAME :GEN_003
PRIORITY :P1
RELEASE_INTRODUCED :7.4 AUTOMATED :NO
STEP_NAME : step1
STEP_DESC :Example desc for understanding second testcase
STEP_RESULT :Example result for understanding second testcase
=cut
=head2 Gen_004
TEST_CASE_NAME :GEN_004
PRIORITY :P3
RELEASE_INTRODUCED :7.4 AUTOMATED :NO
STEP_NAME : step1
STEP_DESC :Example desc for understanding third testcase
STEP_RESULT :Example result for understanding third testcase
=cut';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php