in reply to Converting BCBCBCBCBCCCB to (BC)^{5}CCB

I'd use a regexp to capture the longest string with repeated BC elements, then divide the length of that string by the length of the original BC string to get the exponent, and finish by deleting the stuff just exponentiated.
$Code = "BCBCBCBCBCCCB"; $What = "BC"; $Code =~ m/($What)+?/; $Exp = length ( $1 ) / length ( $What ); $Code =~ s/$1/($What)^($Exp)/e;
This code not tested .. that's just the general idea.

--t. alex

"Of course, you realize that this means war." -- Bugs Bunny.