use strict; my $text='(one dfd(two(three)four()(five)df())df)'; print $& if $text=~m#(\([^()]*(\([^()]*\))+[^)]*\))+#;