# first one my ($start, $middle, undef, $end) = $string =~ /^(.*?)(($pattern)+)(.*?)$/g; # second one, with non-capturing parens -- I like it better my ($start,$middle,$end) = $string =~ /^(.*?)((?:$pattern)+)(.*?)$/g; #### $pattern = 'AB'; 'BABABABBB' =~ / ^ # start at beginning of line ( # capture to $1 .*? # a number of character, but as few as possible ... (?$3$/"; __END__ prints "BBB"