my @columns = qw( Field_1 Field_2 Field_3 ); my $flush = $columns[-1]; # maybe you have a better way of knowing when your set is complete # output header: print join("\t", @columns), "\n"; my %row; while (<>) { if (/(\w+) = (.*)/) { $row{ $1 } = $2; if ($1 eq $flush) { print join("\t", @row{ @columns }),"\n"; }; } else { warn "Unknown line: $_"; next; }; };