You can use the paragraph mode with -00
where records are delimited by empty lines and do something like:
perl -00 -i -pe 's/\b[0Z]:\K0\b/3/g if /^PIN (A|C)\b/' text
(or just if /^PIN [AC]\b/
for single letter PINs).
Or:
perl -00 -i -pe 's/\b[0Z]:\K0\b/3/g unless /^PIN B\b/' text
A more generic approach is to record the current PIN in a variable, and do the substitution when that variable has the value you want:
perl -i -pe ' if (/^PIN (.*)/) { $pin = $1; } else { s/\b[0Z]:\K0\b/3/g unless $pin eq "B"; }' text
That s/\b[0Z]:\K0\b/3/g
replaces the trailing 0 in [0Z]:0
(where \K
is used to mark the start of what is to be K
ept (and thus replaced) from the match) with 3 provided they're preceded and followed by word b
oundaries to avoid it matching 0:0
inside 10:02
for instance. That won't stop it matching inside 1:0:0.3
though as :
and .
are not word characters so there is a word boundary between :
and 0
and between 0
and .
.