\def\foo#1{\bar#1\end} \def\bar#1{\ifx#1\end \let\next=\relax \else Do Something \let\next=\bar\fi \next}