while( $str=~/(Collisionmonitoring\s+between\s+[^\(\)]+?\([\(\)]+\)\s+and\s+[^\(\)]+?\([\(\)]+\))\s(\w+)/sgc ) { print "FOUND $1 ===> $2\n"; }