Perhaps you are looking for something like this instead? :)
use strict; use Data::Dumper; while (<DATA>) { chomp; # remove trailing \n, optional my @rec = split /\|/; # split records my $date = $rec[0]; my ($activity, $machine, $requester) = $rec[2] =~ /(.*)\sfor\s(.*)\s\(requested by (.*)\)/; print "$date, $activity, $machine, $requester\n"; } __DATA__ 10/1/2003 2:06:32 AM|1|Checkout Started for US-02-14@comany.com (reque +sted by aad6870) 10/2/2003 2:07:17 AM|1|Checkout Processed for US-02-14@company.com (re +quested by aad6870) 10/3/2003 2:09:37 AM|1|Checkin Processed for DN-US-02-14@company.com ( +requested by aad6870) 10/4/2003 9:37:53 AM|1|Checkout Started for DN-US-02-14@company.com (r +equested by heavis6608) 10/5/2003 9:38:29 PM|1|Checkout Processed for US-02-14@company.com (re +quested by heavis6608) 10/6/2003 10:10:21 AM|1|Checkout Started for US-02-17@company.com (req +uested by vm_karthik3521)
And the output is -
10/1/2003 2:06:32 AM, Checkout Started, US-02-14@comany.com, aad6870 10/2/2003 2:07:17 AM, Checkout Processed, US-02-14@company.com, aad687 +0 10/3/2003 2:09:37 AM, Checkin Processed, DN-US-02-14@company.com, aad6 +870 10/4/2003 9:37:53 AM, Checkout Started, DN-US-02-14@company.com, heavi +s6608 10/5/2003 9:38:29 PM, Checkout Processed, US-02-14@company.com, heavis +6608 10/6/2003 10:10:21 AM, Checkout Started, US-02-17@company.com, vm_kart +hik3521
I think the only trick here is with the my ($var) = $str =~ /(.*)/; idiom. Which is a handy one to master. tachyon had a Perl Meditation not long ago on this topic... 291543

Also you don't need to print the elements one line at a time, you can print them all at once.


In reply to Re: Regular Expression help by Roger
in thread Regular Expression help 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.