use Regexp::Common; while () { (/$RE{balanced}{-begin => "("}{-end => ")"}/) ? (print "Line $. : Matched: $&\n") : (print "Line $. : Not Matched\n"); } __DATA__ This is my (one dfd(two(three)four()(five)df())df) text. This is my (one text. #### Line 1 : Matched: (one dfd(two(three)four()(five)df())df) Line 2 : Not Matched