#! perl -slw use strict; $/ = "\n1SYSTEM"; ## para mode my @fields; while( my $page = ) { ## Extract date $page =~ m[ACTUALS THRU (\d\d)/(\d\d)] and my $period = "${1}20${2}" or die "Couldn't get date"; ## Extract body and split into lines ## discarding total(*) lines $page =~ m[COST\n(.+)]s and my @lines = grep{!m[^0.\*] } split "\n", $1 or last; for my $line ( @lines ) { my @temp; ## Split the line into fields. Skip the last line eval{ @temp = unpack 'xa5x2a3x2a15x2a6x2a5x2a5x4a5x9a8x4a9x5a5x15a5x4a9', $line; } or last; ## Fill in th missing fields from previous line $temp[ $_ ] =~ m[^\s+$] and $temp[ $_ ] = $fields[ $_ ] for 0, 1, 2, 3; ## output formatted appropriately print join '|', $period, @temp; ## Save fields for in-filling. @fields = @temp; } } __DATA__