#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my @lines = ; 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 "" (captured) \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 (captured) \s+ # required space ([[:alnum:]]+) # part b of U1 format (captured) > # ">" end of U1 format ) # grouping 1.1 end | # or groupings 1.1 & 1.2 (?: # grouping 1.2 start (filename format) " # 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 Format */ #### 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"