$/ = "end-of-record-string"; # whatever that may be while (<>) { # this now reads one whole record into $_ my @lines = split( /\n/ ); my %record while ( @lines ) { $_ = shift @lines; # proceed with parsing record fields as above... if ( /^Request Number:/ ) { ... } elsif ... } store_to_database( \%record ); }