open (FILE, $lfilename) or &dienice; $/ = undef; # Slurp mode $file = (); # Grab the whole file into $file while ($file =~ m/Begin Product(.*?)End Product/gs) { my $record = $1; # Now $record contains the entire contents of exactly one # record from your file. You can now fold, spindle, and # otherwise mutilate $record to pull out the various # and sundry pieces for each record. }