use strict; use warnings; # Locate header: discard lines until we find # a line containing "-----" while () { last if /-----/; } # Gather the headings my @headings; while () { last if /=====/; my @fields = split /%/; for my $i (0 .. $#fields) { $headings[$i] .= $fields[$i]; } } print join(", ", @headings), "\n"; # Extract the data while () { last if /-----/; my @fields = split /%/; print join(", ", @fields), "\n"; }