#! perl -slw use strict; $"=' | '; sub buildFmt { my $templ = shift; my @cols; push @cols, $-[ 0 ] while $templ =~ m[(?<=\s\s)(?=\S)]gc; my $p = 0; my $fmt = ''; $fmt .= 'A' . ( $_ - $p ) . ' ' and $p = $_ for @cols; return $fmt; } ## Slurp the file and break into sections my @sections = split '-{103}', do{ local $/; <> }; close *ARGV; ## Section 1 ## Left as an exercise # Section 2 my @section2 = split "\n", $sections[ 1 ]; shift @section2 for 1 .. 3; ## discard header lines; ## Away my $fmt = buildFmt( shift @section2 ); my @awayStats; push @awayStats, [ unpack $fmt, shift @section2 ] while $section2[ 0 ] =~ m[\S]; print "@$_" for @awayStats; ## Discard blank lines shift @section2 while $section2[ 0 ] !~ m[\S]; ## Away totals $fmt = buildFmt( shift @section2 ); my @awayTotals = unpack $fmt, shift @section2; print "@awayTotals"; ## Discard blank lines shift @section2 while $section2[ 0 ] !~ m[\S]; # home $fmt = buildFmt( shift @section2 ); ## They could vary. my @homeStats; push @homeStats, [ unpack $fmt, shift @section2 ] while $section2[ 0 ] =~ m[\S]; print "@$_" for @homeStats; ## Discard blank lines shift @section2 while $section2[ 0 ] !~ m[\S]; ## Home totals $fmt = buildFmt( shift @section2 ); my @homeTotals = unpack $fmt, shift @section2; print "@homeTotals"; ## Section3 ...