in reply to while (scalar()

that's an incomplete code block. if it were complete, somehow, it would be an infinite loop if there are contents in @ra,@rb, or @rc since no arguments are ever popped or shifted out of the arrays. either it's completely broken or the context which you provide is very incomplete.

also, the code formatting is horrendous!