Three problems:
"|" is a special character in regexps. It needs to be escaped.
You will look for "MSG-HDR" and "|UB" on the same line. The following would match:
MSG-HDR |UB
The next in the code below fixes this.
$orderfound is not always cleared when it should be. The following would match:
MSG-HDR bla |UB
Or maybe that's ok? If it's ok, keep the $orderfound = 0; where it was.
Fix:
my $orderfound = 0; while (my $line = <>) { if ($line =~ /MSG-HDR/) { $orderfound = 1; next; } if ($orderfound && $line =~ /\|UB/) { print "$line\n"; } $orderfound = 0; }
In reply to Re: Matching over two lines
by ikegami
in thread Matching over two lines
by TrekNoid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |