if can conditionally execute statements, but it can't loop. Maybe you meant while? (see perlintro, perlsyn).
Your question seems very generic, but makes very little sense at the same time - please try to give us a much more concrete idea of what you want to do, and what your problem is.