foreach my $item (@cqafiles) { open CQAFILE, "<$item"; while () { next unless /^CQA_STATUS,/; print FILE $'; } }