ask_chinna has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Can we use variable for pattern match and extraction
by kvale (Monsignor) on Jun 26, 2002 at 19:59 UTC
    You are almost correct with the syntax; if you want to match a string against a regex, you will want to use
    ABC: while () { #print "entered into while loop\n"; if ($_ =~ /$net_extract/) { $count = 1; print "hello\n"; }
    -Mark
      And the other thing that might be what you want is:
      ABC: while () { #print "entered into while loop\n"; if ($_ eq $net_extract) { $count = 1; print "hello\n"; }
      These are 2 quite different approaches though, kvale's will execute the loop if any part of $_ matches $net_extract, whereas the in the code above the loop will only execute if $_ and $net_extract match exactly.

      "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!

      Mark,

      I am able to work now, with the following modifications.

      ^\*\|NET\smin_msb_led\0\, look at I have removed the starting and endig slashes.

      then "if ($_ =~ $net_extract)".

      -Chinna