$x=0; for $field (@fields) { next if $field =~ /[modified|META|WhateverYouWant]/; last if $x==$#fields; ## or just this print<<"HTML"; $fs\u$field:$fc HTML $x++; } # End of foreach.