in reply to PERL Regular expression

Please read Writeup Formatting Tips. In particular, code should be wrapped in <code> tags so that formatting is preserved. Note how your character classes got converted to links - this is a direct result of omitting <code> tags.

I looked through the documentation to find you a link on this (perlre, perlretut) but was unable to track one down. Essentially, the problem is that backreferences appear not to work as you seem to expect in a character class. I suspect this is because the backreference is not defined when the pattern is compiled. One work around for you would be to A bit of magic: executing Perl code in a regular expression:

if ( $line =~ /<(\w(?:[^ \/>]+))(?:(?:(?:\s+)([^=>]+)\s*=\s*("|')((??{ +"[^$3]*"}))\3))\s*\/>/) { print ("1=" . $1. "\n2=" . $2 . "\n3=" . $3 . "\n4=" . $4 . "\n5=" +. $5 . "\n"); }

In general, however, when you need to resort to using (?{...}) or (??{...}), you are trying too hard. Your code will likely be fragile and unmaintainable. See point 2 below.

Side notes:

  1. Since double quotes interpolate (Quote and Quote like Operators), you could more simply write your print statement as:

    print ("1=$1\n2=$2\n3=$3\n4=$4\n5=$5\n");

  2. You probably shouldn't be parsing XML yourself as there are plenty of modules to do it for you (XML::Twig, XML::Simple, XML::Parser,...).