use strict; use warnings; my $content = ""; while () { $content = $content . $_; } #print "content: $content"; # sanity check while ($content =~m/( CALCON\([^)]*?\)[\r\n]*{[^}]*?} #entire match. Same as in negative lookahead on next line. ((?!CALCON\([^)]*?\)[\r\n]*{[^}]*?}).)* #inch along with negative lookahead )/xsmg){ my $entire_match = $1; if ($entire_match =~ /CALCON\((.*?)\)/) { my $test_number = $1; print "entire match: $entire_match\n"; print "test number: $test_number\n"; print "\n\n"; } } __DATA__ CALCON(test1) { TYPE(U8) FEATURE(DCOM) NAM(stmin) LABEL(Min seperation time between CFs) MIN(0) MAX(127) UNITS(ms) } CALCON(test2) { TYPE(U16) FEATURE(DCOM) NAM(dcomc_sestmr_timeout) LABEL(DCOM Session Timer Timeout) MIN(0) MAX(65535) UNITS(ms) } CALCON(test3) { TYPE(U16) FEATURE(CALCON) NAM(dcomc_sestmr_timeout) LABEL(DCOM Session Timer Timeout) MIN(CALCON) MAX(65535) UNITS(ms) }