for ($y=0; $y<@lines;$y+=1) { if (($lines[$y]=~/^\*R_/) && ($lines[$y]!~/BADSTRING/)) { do something; } }