Show us the code you tried. For that desired output, the modifications to the code I posted are not that complicated, especially with the suggestions that I already made. What I already said about collecting values from MYFILE will still work. Here are some additional hints to create the output you want:

For each line from NEWF, you need to check the index in column 5 and the A/B label in the last column. You get your hands on each of those with something like this:

my @fields = ( split /\s+/ ); # need to hold on to all field+s for later
my( $index, $label ) = @fields[4, -1]; # this is an array slice

Now that you know the index and the label for a line, you use them to find the proper value from one of the arrays you created while reading from MYFILE (e.g., @a_vals or @b_vals if you followed my example). As I mentioned, before, you can use if/else to do that but a nicer way is with given/when (as long as your Perl is 5.10.0 or newer). Here's a suggestion but note that it will not work as written here. $x and $y are not declared. You need to replace them with the correct value from @a_vals or @b_vals (HINT: use $index from above).

You need to check the value of $index to get the values for type 'A' into @a_vals, similarly for the 'B' values. The way you have it, you only get 'B' values because they are the last ones in MYFILE, and you are putting the same things into both @a_vals and @b_vals. Since the 'B' values come in last, they overwrite the corresponding 'A' values in @a_vals. You can use the same kind of if/elsif/else logic as in your other loop to fix this(but see comments below on ways to improve that).