I guess the split converts only the caps in the $B and then I print the non_exmpty strings. Please let me know where I am totally wrong. I thought the $A was discontinuous, but the order of the characters remained the same and hence thought I could do it this way.
Ah.. okay, I see what you were trying to do. The problem is that's not what the original poster needed - distinguishing by capitalization won't work for his real data set where instead of the wxyz there will be ACGT characters. So you have to try and find consecutive sequences out of $A in the right order inside $B, taking into account extra ACGT sequences in $B.