This idea looks like it is in the right direction.
If the address you seek is between a VAT line and a DESCRIPTION line, and that's the way that it always is, then, something like this might help?

This code looks for non-blank lines between and including lines starting with VAT and DESCRIPTION. So throw away those lines and any blank lines. The "trick" then comes down to figuring out when the address ends. If it is possible to write a simple regex that fits a UK postal code, then no state machine is required (when you see the postal code, the address record is done). Below I threw in an extra line feed when I see the postal code. Many variations are possible! Anyway, just an idea for you... Maybe this doesn't work if postal code is too variable and of course you'll have to refine my regex... But maybe this will spark another idea?

while (<DATA>) { if (( /^VAT/.../^DESCRIPTION/) && (!/^s*$/)) { next if /^VAT/; next if /^DESCRIPTION/; print; #these are the address lines print "\n" if (/\w+\d \d/); #the trick is to see #when address is done, eg a postal code } } __END__ prints: Miss Carol Hocker 177 Elm Road, Brighton East Sussex BN2 7HB Mr Whatever 177 Elm Road, Brighton East Sussex BN2 7HB __DATA__ Invoice Invoice No: C0331-2008 Invoice Date:27/02/2008 VAT No: 679 7113 03 Miss Carol Hocker 177 Elm Road, Brighton East Sussex BN2 7HB DESCRIPTION blah..blah Invoice No: C0331-2008 Invoice Date:27/02/2008 VAT No: 679 999 03 Mr Whatever 177 Elm Road, Brighton East Sussex BN2 7HB DESCRIPTION ...something here....

In reply to Re^4: Extracting a (UK) Address by Marshall
in thread Extracting a (UK) Address by ropey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.