You have a lot going on here, but not necessarily all in the correct order. The first thing that jumps out at me is this:
-
@words = split " ", @string;
-
You have that defined inside of your foreach loop, but are using the array @words as an argument to your foreach loop. This, I am afraid, is not possible. You must put that outside of the foreach loop so that it is defined before the foreach loop is entered.
Next, in that code snippet above, you reference @string, but it isn't defined anywhere, but $string is.
Do me a favor please. Clean up your code so that it flows properly and if you could, paste all of your code here if it isn't already. Then, please give a better explanation of exactly what you are wanting to do, along with a sample of the data you are referencing, so we know what we are working with.
Regards,
Jeff