#!/usr/bin/perl while(){ if (/^(\[\w+\])/) { # New block starts $line =~ s/\<$/

/ if $f eq 'NEW'; # Replace the < by

for NEW blocks only $f = $1; } defined($line) and print $line; # Print the last line $line = $_; # keep for next run # Save this line } print $line; # Print last line __DATA__ [NEW] Dear Carolyn: My husband and I divorced after 42 years. It didn't tak +e long for him to find a replacement, but I was happy for him at the time.< them and let my grandchildren dig through her purse as if she were the +ir grandmother.< [OLD]