my $match; $match = qr/(?:\((?:(?>[^\(\)]+)|(??{$match}))*\))/; if ( $text =~ /($match)/ ) { print $1; # text between nested ( and ) }