in reply to (Golf) Gödel, Escher, and Bach, Oh My!

Here's my solution. It's 184 characters:
sub mu { for(@s=($_[0],$c=0);$c<$_[2];){($_=shift@s or$c++,$s[@s]=0,next )eq$_[1]&&return$c;$s[@s]="$_$1"if/^M/;/I$/and$s[@s]=$_.U;$s[ @s]="$`$'"while/UU/g;$s[@s]=$`.U.substr$',2while/I(?=II)/g}0 }
I believe it handles all the cases correctly. Here are the tests I used:
print mu( "MUUUU", "M", 20 ); # returns 2 print mu( "MI", "MU", 7 ); # returns 0 print mu( "MI", "MI", 20 ); # returns 0 print mu( "MI", "MUIUI", 20); # returns 4 print mu( "MI", "MUIUI", 3 ); # returns 0 print mu( "MIIII", "MIU", 4); # returns 1 print mu( "MI", "MIIU", 4); # returns 2
The second to last line tests rule 3 where there are four Is in a row, and the last line tests rule 1.

I switched the limit on the second test from 20 to 7 because I didn't have the patience to wait for the sub to run through all the possibilities to 20 steps. :)