use strict; use warnings; open F, '<', '782426.txt' or die; $/="\r\n"; binmode F; my $last_key; my $record = {}; my @records; while () { s/^//; # kill that pesky thing. /^\s+NEW CAR INV prepared by / and scalar(), next; # the header /^[\.\s]*$/ and next; # skip any blank lines /^\d+ records listed\./ and last; # end of report chomp; my($key,$val) = /^(.{19}) +(.*)/; if ($key=~/\S/) { $key =~ s/\.+$//; # kill trailing dots $record->{ $last_key=$key } = $val; } elsif(defined $last_key) { $record->{$last_key} .= $val; } if ( $key eq 'SALES CST' ) # last line of record { push @records, $record; $record = {}; } } close F; for my $record ( @records ) { print "$_='$record->{$_}'\n" for sort keys %$record; print "\n"; }