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


in reply to Converting multiple lines into single line.

On the other hand, if you insist on reading a line-at-a-time, let's just define lines to end on a '}';

#!/usr/bin/perl # http://perlmonks.org/?node_id=1206966 use strict; use warnings; local $/ = '}'; while(<DATA>) { s/^war \V* \K \{ .* \}/ $& =~ tr|&\n||dr /emsx; print; } __DATA__ some starting text war eligible, init =0*DEC0, ev (VARIABLE){1*BIN0,2*DEC3,6*BIN4, & 5*BIN43,6*DEC32, & 5*BIN43,7*DEC32} some other text war wear, init =1*DEC1, ev (VARIABLE) { & 1*BIN0,2*DEC3,6*BIN4, & 5*BIN43,6*DEC32, & 5*BIN43,7*DEC32,6*DEC32,6*DEC3, & 8*BIN3,6*DEC34 } some final text

Outputs:

some starting text war eligible, init =0*DEC0, ev (VARIABLE){1*BIN0,2*DEC3,6*BIN4, 5*BIN4 +3,6*DEC32, 5*BIN43,7*DEC32} some other text war wear, init =1*DEC1, ev (VARIABLE) { 1*BIN0,2*DEC3,6*BIN4, 5*BIN43, +6*DEC32, 5*BIN43,7*DEC32,6*DEC32,6*DEC3, 8*BIN3,6*DEC34} some final text