$_ = qq(For eg., if the text is given as I am (giving this (text to (tell you) that this) will give) you the result. In this case, I need the phrase, (giving this (text to (tell you) that this) will give) This should hold for any number of nested paranthesis.); (my $re = $_) =~ s/((\()|(\))|.)/${['(','']}[!$2]\Q$1\E${[')','']}[!$3]/gs; print eval{(/$re/)[0]},"\n"; warn $@ if $@;