@moves = qw(R U R' U' R' F R2 U' R' U' R U R' F');

$state = 'UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR';
%turns = (U => 'FLBR', D => 'FRBL', R => 'FUBD', L => 'FDBU', F => 'URDL', B => 'ULDR');

sub move {
  my ($pos) = @_;
  ($cycled = $turns{$side}) =~ s/(.)(.*)/$2$1/;
  eval "\$pos =~ y/$turns{$side}/$cycled/";
  $pos;
}

print "Moves: @moves\nStart: $state\n";
for $move (@moves) {
  $move =~ s/'/3/;
  ($side, $angle) = split //, $move . 1;
  $state =~ s/\w*$side\w*/move($&)/ge while $angle--;
}
print "End:   $state\n";