Thanks Phil for useful advice. BTW I created 3 subroutines that cover most of cases in Text::Balanced What do you think ?
###################################################################### +####### #Input file Looks Like: #SingleLinesMultiLineFile #START_TAG\ value1 \END_TAG #SomeChar #START_TAG\ value2 \END_TAG #SomeChar #START_TAG\ value3 \END_TAG #SomeChar #end SingleLinesMultiLineFile #Usage: #$InputFile="$LocationOfTheScriptsDirectory\\MultiLine.txt"; #$StartTag='START_TAG\\'; #$EndTag='\END_TAG'; #@AValues=getInfoFromSingleLinesMultiLineFile($InputFile,$StartTag,$En +dTag); #Result:@AValues=qw(value1 value2 value3); sub getInfoFromSingleLinesMultiLineFile { my ($InputFile,$StartTag,$EndTag)=@_; my ($line,@wanted_substrings); #Openning file for reading open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; while($line=<IFH>) { if($line =~ /\Q$StartTag\E(.*?)\Q$EndTag\E/) { push(@wanted_substrings,$1); } } return @wanted_substrings; } ###################################################################### +####### #Input file Looks Like: #MultipleLinesMultiLineFile #SomeChar # START #value # END #AnotherChar #end MultipleLinesMultiLineFile # #Usage: #$InputFile="$LocationOfTheScriptsDirectory\\MultyLine.txt"; #$StartTag='START'; #$EndTag='END'; #@StartEnd=getInfoFromMultipleLineMultiLineFile($InputFile,$StartTag,$ +EndTag); sub getInfoFromMultipleLinesMultiLineFile { my ($InputFile,$StartTag,$EndTag)=@_; my ($line,@wanted_substrings); #Openning file for reading open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; while($line=<IFH>) { if (($line =~ m/\Q$StartTag\E/) .. ($line =~ m/\Q$EndTag\E/)) { push(@wanted_substrings,$line); } } return @wanted_substrings; } ###################################################################### +####### #Input file for longline: #SingleLineSingleLineFile<A>AAA</A><B>BBB</B><C>CCC</C><A>123</A><D>DD +D</D><A>HHH</A><C>CCC</C>end SingleLineSingleLineFile #Usage: #$InputFile="$LocationOfTheScriptsDirectory\\LongLine.txt"; #$StartTag='<A>'; #$EndTag='<\A>'; #@AValues=getInfoFromSingleLineSingleLineFile($InputFile,$StartTag,$En +dTag); #Result:@AValues=qw(AAA 123 HHH); sub getInfoFromSingleLineSingleLineFile { #Openning file for reading my ($InputFile,$StartTag,$EndTag)=@_; my ($line,@wanted_substrings); open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; $line = <IFH>; #1 #my @wanted_substrings = $line =~ /<A>(.*?)<\/A>/g; #2 #push(@wanted_substrings,$1) while $line =~ /<A>(.*?)<\/A>/g; #3 while ($line =~ /\Q$StartTag\E(.*?)\Q$EndTag\E/g) { push(@wanted_substrings,$1); } return "@wanted_substrings"; }

In reply to Re^3: Regular Expression problem when Extracting Start\ VALUE \End by gasho
in thread Regular Expression problem when Extracting Start\ VALUE \End by gasho

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.