my ($start,$middle,$end) = $string =~ /^(.*?)(($pattern)+)(.*?)$/g; #### my ($start,$middle,undef,$end) = $string =~ ...