If the Ids are unique this is of course a good solution, but if not this has a caveat... if there happen to be two Success sections with the same Id right after each other, the second one won't be matched unless the second regex is changed accordingly:
use warnings; use strict; my $ID = '5678'; while (<DATA>) { my $match = /^Success.*Id-\Q$ID\E/i ... /^Success.*Id-(?!\Q$ID\E)/i; print if $match && $match !~ /E/; } __DATA__ One Success|Id-abcd Two Success|Id-1234 Three Success|Id-abcd Four Success|Id-5678 Five Success|Id-5678 Six Success|Id-9900 Seven Success|Id-5678 Eight Success|Id-0000 Nine
In reply to Re^2: Search after match in dynamic lines
by haukex
in thread Search after match in dynamic lines
by leoberbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |