in reply to Help with my rookie logic
Unterminated <> operator [download]
The following:
... and $orig_cnt=1) [download]
is an assignment. It should probably be a numeric check (==):
... and $orig_cnt==1) [download]
I also see that in two other places in your code.
Other advice: