# "What I essentially need is a way to say..." my $start_tag = 'BEGIN'; my $end_constant = 'END'; my $headerformat = join('; ', "%s=%s" x 17)."\n"; # XXX ? format for printf() ? my $headerfile = 'header000'; my $detailsection = 'detail000'; open IN, '<', $file) or die "Can't read '$file': $!\n"; RECORD: while(defined($_ = )) { my %out; # we'll capture the "record content" for printf() here if (/$start_tag/) { # "...start at this character..." $. = 0; # reset line counter while() { # "...read each line for the next 17..." # XXX the specs aren't clear her. my ($key, $value) = split; # so I'll just split $out{$key} = $value; # "...assign to values to do # a printf statement..." if($. == 17) { # done with reading the record. do "the printf()" open HEADER, '>', $headerfile or die "Can't write to '$headerfile': $!\n"; printf HEADER $headerformat, map { $_,$out{$_} } keys %out; close HEADER; $headerfile++; # string increment: header000 -> header001 $. = 0; open DETAIL, '>', $detailsection or die "Can't write to '$detailsection': $!\n"; # "starting at the 18th line of that record..." while() { # "...read until the end constant..." print DETAIL; # "...and print that straight to # a different file..." last if /$end_constant/; } close DETAIL; $detailsection++; next RECORD; # "...and then start the entire loop again." } } } }