Just move the condition outside the loop; if you know what member of a row to test, test just that (i.e. $stat_array_rows[2], otherwise you can use grep. Your code is buggy: why do you use $stat_row[0], when the only stat_row variable is a scalar? Use strict and warnings!