Thank you toolic..please see the reduced version of the code..
use strict; use warnings; FindInHorizontalRegion('SETTINGS:Flight','SETTINGS:Tick','1000',10); #FindInHorizontalRegion('Flight','SETTINGS:Tick','1000',10); sub FindInHorizontalRegion { print "Inside FindInHorizontalRegion \n" ; my ( $element1,$element2,$duration,$threshold) = @_; my $regex1 = '(.*?)\:(.*?)' ; print "The first element is $element1 \n....The second element is +$element2 \n... Entering if condition for the first time to check if +it is text or image \n"; if ( $element1 =~ m/$regex1/g ) { print "The regex is matched and the first element is an image\n"; } else { print "THe first element is text \n"; } if ( $element2 =~ m/$regex1/g ){ print "The second element is an image \n"; } else { print "THe second element is text \n"; } print "Horizontal coordinates obtained \n"; if ( $element1 =~ m/$regex1/g) { print "To check for Image \n"; } else { print "To check for Text \n"; } }
The output that I need for this is - The CORRECT OUTPUT

Inside FindInHorizontalRegion
The first element is SETTINGS:Flight
....The second element is SETTINGS:Tick
... Entering if condition for the first time to check if it is text or image
The regex is matched and the first element is an image
The second element is an image
Horizontal coordinates obtained
To check for Image

but the output that I am getting is different in the last line.. The output that I GET

Inside FindInHorizontalRegion
The first element is SETTINGS:Flight
....The second element is SETTINGS:Tick
... Entering if condition for the first time to check if it is text or image
The regex is matched and the first element is an image
The second element is an image
Horizontal coordinates obtained
To check for Text

The regular espression has to do this, if there is a : in the string, it is taken as Image else Text. The regular works fine the first time, but after Horizontal coordinates are obtained..it prints To check for text instead of printing To check for image. I hope you can understand now.

In reply to Re^2: Regex not working by Perllace
in thread Regex not working by Perllace

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.