I have a file structured like this: 1. This is a heading ....... 1.1. A subheading 1.2. Another subheading 2. Another heading ...... 3. Yet another heading .....
I want to extract (a) each heading number with the matching heading text, and (b) the immediately following text up to, and not including, the first subheading. I got the first part, but not the second: my $counter = 1; my %headinghash; open (FILE, "<test.txt") || die ("can't: $!"); while (<FILE>) { my $file = $_; chomp($file); if ($file =~ /^($counter)\.\s(.*?)$/) { $headinghash{$counter} = $2; #missing code here, need data up to next occurrence of "$counter.1" $counter++; } } close (FILE); I need the regexp to take off at that point where there was a match for the heading, and then extract everything from there up to the occurrence of "$counter.1". Would this necessarily involve slurping the whole file into an array first? Thanks in advance for any advice, Birgit Kellner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]