Reason its failing because csh has foreach loop no other shell does. so if you try to execute the script by anyother shell it will fail.
since you already have #!/bin/csh
you can execute the script using ./scriptname
but if you are intended to execute it within someother shell------
replace for each line with following
for sub in $(echo "all the strings seperated by a space")
do
\# rest of your script inside for should come here
done #done is replacing end in your case
if you cannot use echo "string SEPERATED by spaces"
then you can use cut
with the delimeter you have.
I am not able to figure our delimeter you are using in foreach statement.