Take a look at these articles and see if you can adapt these techniques to your needs:
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/64014/
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/99287/
http://www.codeproject.com/Articles/14341/Using-the-Foreach-ADO-Enumerator-in-SSIS