####program.pl #!/usr/bin/perl use strict; use warnings; use Text::Balanced 'extract_bracketed'; my $delim = '([{<'; my $prefix = qr{[^\Q$delim\E]*}; my $string = 'The use of parentheses (indicates that the (writer [considered] the {information}) less an afterthought).'; my @parts = extract_bracketed($string, $delim, $prefix); $parts[2]=~s/\s*$//; print WF1 "pattern:\'$parts[0]\'\n"; print WF1 "rightside of pattern:\'$parts[1]\'\n"; print WF1 "leftside of pattern:\'$parts[2]\'\n"; #### pattern:'(indicates that the (writer [considered] the {information}) less an afterthought)' rightside of pattern:'.' leftside of pattern:'The use of parentheses' #### $string = 'The (use {of}) parentheses (indicates that the (writer [considered] the {information}) less an afterthought).'; Output: pattern:'(use {of})' rightside of pattern:' parentheses (indicates that the (writer [considered] the {information}) less an afterthought).' leftside of pattern:'The'