in reply to Re^2: match lines containing state abbreviation
in thread match lines containing state abbreviation

Splitting the lines to create an array is probably what I would have done. However, if you want to work directly with a multiline string, here's one way to do it:

$ perl -Mstrict -Mwarnings -E ' my $lines = "AZ\nSX\nAZ\nDC\nAB\nYZ\n"; say $lines; $lines =~ s/(?>[^A].|.[^Z])\n//gm; say $lines; ' AZ SX AZ DC AB YZ AZ AZ

In my opinion, the multiline solution is a lot more cryptic than the array solution.

-- Ken