#!/usr/bin/perl -w use strict; my @buf = ; chomp @buf; # chop of all the line endings my $doc = join ' ', @buf; # one nice juicy line my $doc_id = qr(\d+\.\d+\.); # precomp regex - also self documenting while ($doc =~ /($doc_id)\s+(\w+)(.*?)Prototype:.*?(?=$doc_id)?/g) { print "$1 $2 $3\n"; } __DATA__ 5.1. GetAFunctionHere This is the description of a function Which spans a few lines Prototype: int GetAFunctionHere(int *count) Parameters: *count probably some kind of spelling object 5.2. GetMoreFunctionsHere This is the description of another function Which spans a few more lines Prototype: int GetMoreFunctionHere(float *crash) Parameters: *crash probably some kind of rowing object