in reply to Splits and Arrays, PLEASE HELP:D

Here's an answer, not necessarily the best, to PART 2, at least the string transformation portion thereof, but I'd strongly suggest you understand all of it before submitting it to your instructor lest embarrassing questions be asked. (See List::Util for the  sum() function)

>perl -wMstrict -le "use List::Util qw(sum); ;; my $s = 'r1y2g3g4y2r4r3y5y3g3g6g2r1'; my $r = 'r 1 y 2 g 7 y 2 r 7 y 8 g 11 r 1 '; ;; $s =~ s{ (([[:alpha:]]) \d+ (?: \2 \d+)*) } {$2 ${ \sum $1 =~ /\d+/g } }xmsg; print qq{'$s'}; ;; $s eq $r or die 'not what was wanted'; " 'r 1 y 2 g 7 y 2 r 7 y 8 g 11 r 1 '

Notice that I had to cheat a bit to make this work: the extra space at the end of the  $r "required output" string. Can you alter the substitution to get rid of this extra space, perhaps by adding a  (\z)? or  (\Z)? term to the regex and modifying the replacement expression accordingly?