in reply to A way to avoid repeated conditional loops

The below is one way:
Keep things simple.
Output of below is: term 'alpha' detected on input line 4
The code below is very efficient and runs fast.
#!usr/bin/perl -w use strict; while (<DATA>) { if(/\balpha\b/) { print "term 'alpha' detected on input line $.\n"; next; } .. do something here... .. sometimes better than elsif() } __DATA__ beta beta beta alpha # this line appears only once in the whole file beta beta beta
if you have a lot of conditions, then perhaps something like this is appropriate:
while ( <FILE> ) { if ( /alpha/ ) { .... next; } if (/beta/) { .... next; } #here is the default code... }
One of the reasons to do it that way is so that all of the conditions can be interchanged with one another. If you have an if(..)elsif(..)else(..) conditional, this hinders the ability to change the order of the conditions. At the end of the day, that approach will result in more complex code and limit the ability to re-order the code's priority of matching - don't do it. At least for number of "if" statements of about 5-6.

Update: Well this is one of those situations where there just isn't a "one size fits all" solution. I tend to prefer coding with several sequential if{..} statements so that all of them are "equal". This whole coding style discussion can set off something that will last until a gallon of gas falls back to $1.60.