Brethren

I seek to split text, based on a bunch of keyword in the text, and shove it into a hash. I've been staring at 'Chapter 6: Pattern Matching' in the Perl Cookbook, but I just can't seem to get my mind around it. I'm pretty sure I need to be using the \G anchor, and non-greedy matching, but... I have an array of keywords like

$Keyptr = {PREFACE => 1, ANALYSIS => 1, DEFERRED => 1, 'NAME / NUMBER' => 1, CONCLUSION => 1, EFFECTS => 1, REMARKS => 1}

My input looks like

@inputs = ("fronttrash PREFACE: mumble ^M ANALYSIS: yada ^M yada CONCLUSION: d +rone drone ^M REMARKS: ixnay", "ANALYSIS: Chuckle REMARKS: Yada2 DEFERRED: blahblah ^M blah ^M NAM +E / NUMBER: John 369")
I want to coerce it into something like
[{PREFACE => "mumble", ANALYSIS => "yada ^M yada", CONCLUSION => "drone drone", REMARKS => "ixnay"}, {ANALYSIS => "Chuckle", REMARKS => "Yada2", "NAME / NUMBER" => "John 369", DEFERRED => "blahblah^M blah"}]
Is this the thing that can /should be done in a single golfed line? Alternatively, is there a module that I should be looking at?

Thanks
Throop


In reply to Regex help - butchering text into paragraphs by throop

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.