while ($inline = ) { @mag = split(/\s+/, $inline); next unless $mag[12] >= 12 && $mag[12] <= 20; #the rest of your code here, using @mag instead of @firstline; }