If your files aren't too big, you can slurp the file into a single string. Then you can get the info you need with a simple regex that employs a 'g' flag to get all the matches:

my $text; { local $/ = undef; $text = <DATA>; #"slurp" the whole file } while ($text =~ / (\d+) \. pace (.*?) \d+ \. slow /xmsg ) { print "filename=$1 and text=$2"; } __DATA__ 12345.pace text1 12345.slow 123456.pace text2 123456.slow hyds.pace bla bla bla uiw.slow --output:-- filename=12345 and text= text1 filename=123456 and text= text2

I'll leave the file creation and the writing of the file for you.


In reply to Re: copying lines in a text file to a new file with a dynamically generated text name by 7stud
in thread copying lines in a text file to a new file with a dynamically generated text name by seek_m

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.