After a little tidying to turn the code into a stand alone sample I don't see the problem you describe given the data you've supplied. Consider:

use strict; use warnings; my $match = 'ArAuthFrameworkImpl::doPostAuth.*Authentication\s*mechanism\s*ret +urned\s*\[(..*­)\]\s*for\s*AuthIdentity\s*\[(..*)\]'; my $outText; open my $outFile, '>', \$outText; while (my $line = <DATA>) { chomp ($line); if ($line =~ /^(.*)INFO:.*QNA Step - AUTH IN PROGRESS/) { my $Time_Stamp = $1; printf $outFile "$Time_Stamp,"; QnA_search_for_sucess_or_failure (); } } close $outFile; print "\n\n$outText\n"; sub QnA_search_for_sucess_or_failure { while (my $line = <DATA>) { if ($line =~ /QNA Auth.*Success\s*and\s*Complete/) { printf $outFile "Success,"; print "In Success,\n"; my $ErrorMsg = "null"; while ($line = <DATA>) { if ($line =~ /$match/) { print "$2\n"; printf $outFile "$2, ${1}, $ErrorMsg\n"; return; } } } if (defined $line and $line =~ /Message.*QNA\s*Auth\s*Failed\((..*)\).*/) { my $ErrorMsg = $1; printf $outFile "Failure,"; print STDOUT "In Failure,\n"; while ($line = <DATA>) { if ($line =~ /$match/) { print "$2\n"; printf $outFile "$2, ${1}, $ErrorMsg\n"; return; } } } } } __DATA__ Tue May 19 22:55:13.649 2009 Morocco Standard Time INFO: pid 2172 t +id 3412: 160: 10083504: QNA Step - AUTH IN PROGRESS Tue May 19 22:55:13.649 2009 Morocco Standard Time INFO: pid 2172 t +id 3412: 160: 10083504: QNA Auth - Success and Complete, Returning SU +CCESS Tue May 19 22:55:13.665 2009 Morocco Standard Time INFO: pid 2172 t +id 3412: 17: 10083504: ArAuthFrameworkImpl::doPostAuth::1:10083487:: +Authentication mechanism returned [0] for AuthIdentity [12345] and for QnA failure the line comes like this in place of success line- +- Tue May 19 22:56:21.962 2009 Morocco Standard Time INFO: pid 2172 t +id 688: 160: 10083554: Err[115261735], Message: QNA Auth Failed(Inval +id Credentials), Repeating the challenge and Returning FAILED

Prints:

In Success, Tue May 19 22:55:13.649 2009 Morocco Standard Time ,Success,

True laziness is hard work

In reply to Re: wrong output by GrandFather
in thread wrong output by namishtiwari

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.