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