$re = '/^(?!021|031)\d*/m';
$str = '022 123-456-2322
021 123-456-2322
031 123-456-2377
041 123-456-2322
021 555-456-2322
031 555-456-2322
0341 555-456-2322
021 123-456-2377
0341 123-456-2377
0341 123-021-2377
0341 123-031-2377';
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