in reply to How to parsing quoted strings in my case.

Your post would be clearer if you used <code>...</code> tags around your code and data. (You can still go back and add those I think.)

I'm guessing at the real format of your input data, since I think you might have two lines run together. The following might do what you want:

#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my @lines = <DATA>; check3($_) foreach @lines; sub check3 { my ($str) = @_; if ($str =~ m{ ^ # Beginning of line \s* # optional space constant # "constant" \s+ # required space (fixup|/\*fixup\*/|) # "fixup" or "/*fixup*/" or "" (captur +ed) \s* # optional space (private|) # "private" or "" (captured) \s* # optional space (\w+) # type/typedef name (captured) \s* # optional space = # "=" \s* # optional space (?: # grouping 1 start (?: # grouping 1.1 start (U1 format) < # "<" start of U1 format ([[:alnum:]]+) # part a" of U1 format (captur +ed) \s+ # required space ([[:alnum:]]+) # part b of U1 format (captur +ed) > # ">" end of U1 format ) # grouping 1.1 end | # or groupings 1.1 & 1.2 (?: # grouping 1.2 start (filename for +mat) " # Filename start quote ([[:alnum:]_/\\\.:]+) # Filename (captured) " # Filename end quote ) # grouping 1.2 end ) # grouping 1 end \s* # optional space (?: # grouping 2 start /\*\s*(.*?)\s*\*/ # "comment" or undef (captured +) | # or # blank ) # grouping 2 end }x ) { print "3: MATCH\n"; my ($fixup,$private,$name,$u1a,$u1b,$filename,$comment) = ($1, +$2,$3,$4,$5,$6,$7); print "fixup=\"$fixup\" "; print "private=\"$private\" "; print "name=\"$name\" "; print "u1a=\"".(defined $u1a ? $u1a : "undef")."\" "; print "u1b=\"".(defined $u1b ? $u1b : "undef")."\" "; print "filename=\"".(defined $filename ? $filename : "undef"). +"\" "; print "comment=\"".(defined $comment ? $comment : "undef")."\" + "; print "\n"; } else { print "3: Sorry Charlie\n"; } } __DATA__ constant fixup private AlarmFileName = "C:\TMP\ALARM.LOG" constant fixup ConfigAlarms = <U1 0> /* U1 Format */

Here's the output I get:

3: MATCH fixup="fixup" private="private" name="AlarmFileName" u1a="undef" u1b=" +undef" filename="C:\TMP\ALARM.LOG" comment="undef" 3: MATCH fixup="fixup" private="" name="ConfigAlarms" u1a="U1" u1b="0" filename +="undef" comment="U1 Format"