http://www.perlmonks.org?node_id=896279


in reply to regex replacement help

Instead of changing the tildes, use them as anchors to change the characters around them.
s/(\w)~(\w)/$1\n$2/g
--marmot

UPDATE: Changed second $1 to $2. Stupid fingers...

UPDATE2: Just realized it was wrong, as well. What was I thinking??? This should do it.

s/~/\n/g; chomp;

Replies are listed 'Best First'.
Re^2: regex replacement help
by choroba (Cardinal) on Mar 31, 2011 at 11:06 UTC
    $2