in reply to Skipping data on file read

Just want to point out that this will cause problems (i.e. an infinite loop) if you hit EOF (end of file) here:
$line = <$FILE>; until ( $line =~ /^c/ or $line =~ /^mt?\d+/ ) { ... $line = <$FILE>; }
I like to write my parsing loops so that I only read lines in one place - like in the outer while statement. Then I only have to check for EOF in one place.

Also, here's a simpler way to look at the problem. You have three kinds of lines:

You can write a simple "event processing" loop as follows:
while (<$FILE>) { if (m/^m/) { ... } elsif (m/^\s/) { ... } elsif (m/^c/) { ... } else { die "whoops - didn't expect: $_" } }
Now you just have to work out what to do in each of the three cases. My suggestion is to create a variable to represent the current m-block being recognized. The actions for each type of line would go something like this: Also, at the end of the loop you'll have to see if there's a block that needs to be processed.