Consider this then.
Make a nested if statement taking in consideration the phrasing of new subs and resubs.
By using that consideration use that to make the response to the sub/re-sub.
Then try using variables for counting. Try /help variables and read through that help file.
Once you do that, use the code offered by Belhifet and modify it to your specification.
If you need extra help with variables you can always use
http://en.wikichip.org/wiki/mirc/variables which contains the same information as the help file, but offers examples as well.