You can do this by extracting the multi-line data items in one go then replacing all but the last newline in each by using regular expressions. Like this

use strict; use warnings; # Slurp data. # { local $/ = undef; $_ = <DATA>; } # Construct regular expression to pull out each data # item; use extended syntax and single-line matching # (i.e. a . matches newline). # my $rxExtract = qr{(?xs) (.+?) # capture one or more characters # with non-greedy matching (?= # zero-width look ahead (?: # alternation group, either \d+\t # digits then a tab | # or \z # end of string ) # close alternation ) # close look-ahead }; # Global match to pull data items out of string. Then # replace all but the last newline in each data item # with tabs. Print items out. # my @items = /$rxExtract/g; s/\n(?=.)/\t/g for @items; print @items; __END__ 1 John Doe, Joe Bloggs title journal Animal Female Protein 2 Mary Clary title magazine Fish Nor Fowl 3 Charley Farley, Piggy Malone title book The Phantom Raspberry Blower

This produces

1 John Doe, Joe Bloggs title journal Animal Female P +rotein 2 Mary Clary title magazine Fish Nor Fowl 3 Charley Farley, Piggy Malone title book The Phantom + Raspberry Blower

I hope this is of use.

Cheers,

JohnGG


In reply to Re: Edit complex file by johngg
in thread Edit complex file by Anonymous Monk

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.