This works most of the time, but for some of these blobs, like this one, I get "02" for an answer instead of "ZKQMR_ INSP"

uh, no?

$_ = do { local $/; <DATA> }; s/\n//g; my ($prog) = $_ =~ /PROGRAM=(.*)\\/ or die("No match\n"); print("Program: $prog\n"); __DATA__ SAOHXXX20090209XXX020607XXXchazerpap07_PRD_00XXX1XXXN0013IT_ QALS-LWEDTL000216V000820090207X000800000000X000800000000X000 833333333X000820090207N0004JESTL000268V0034 000X00340000000000000000000000000000000000X003 400000000000XXX00000000000000000000000X003422222222222222222 22222222222222333X00340000000000000000000000000000000000N001 4<%_TABLE_MAKT>L0003204V0003???X0006??????X0006??????N0009IT _LIST[]L00018V0019Table IT_104[2x76XXX0]TH034\PROGRAM=ZKQMR_ INSP\DATA=IT_LIST[]TH100Table reference: 56 TH055TABH+ 0(20 ) = FFFFFFFCC883EE98FFFFFFFCC895FBB800XXX000000TH055TABH+ 20 (20) = 000000380000006800000002000002F8FFFFFFFFTH047TABH+ 40 (16) = 0400000000004040001024C401800000TH033store = 0 xFFFFFFFCC883EE98TH033ext1 = 0xFFFFFFFCC895FBB8TH033 sXXXhmId = 0 (0x00000000)TH033id = 56 (0x00000038)TH033label = 104 (0x00000068)TH033fil l = 2 (0x00000002)TH033leng = 760 (0x0 00002F8)TH033loopXXX = -1 (0xFFFFFFFF)TH026xtyp = TYPE#000328TH033occu = 16 (0x00000010)TH039acce ss = 1 (ItAccessStandard)TH034idxKind = 0 (ItIndexNone)TH034uniKind = 2XXX(ItUniqueNon)TH030keyK ind = 1 (default)TH032cmpMode = 8 (cmpMany Eq)TH016occu0 = 1TH016groupCntl = 0TH016rfc = 0TH016unShareable = 0TH017mightBeShared = 0TH020sharXX XedWithShmTab = 0TH016isShmLockId = 0TH016gcKind = 0T H016isUsed = 1TH016isCtfyAble = 1TH039>>>>> Shareabl e Table Header Data <<<<<TH033tabi = 0xFFFFFFFCC881F DE8%M
Program: ZKQMR_INSP

Possible problem elsewhere: You're using $1 without checking if the search matched.

$_ = "xxxxx FOO=02 xxxxx PROGRAM=ZKQMR_INSP xxxxx"; /FOO=(\d+)/; /PROGRAM=(.*)\\/; my $program = $1; print("$program\n"); # 02

Possible unrelated problem: Do you realize /(.*)\\/ will match until the *last* \\ in $_? I think you want /([^\\]*)\\/.

Update: Added second code snippet.


In reply to Re: Very Strange Result from REGEX by ikegami
in thread Very Strange Result from REGEX by rementis

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.