An efficient alternative to:
while (<DATA>) {
$_ .= <DATA>;
s/^0\s*(.*)\n\s+(.*\n)/$1 $2/s;
print;
}
is not to even loop at all.
{ local $/ = undef;
$_ = <DATA>;
s/^0\s*(.*)\n\s+(.*\n)/$1 $2/s;
print;
}
caveat is that it eats up memory if you have an extremely large file.
Cheers,
Kristina
Update: See BrowserUK's post immediately below. /s would allow the "." to match the newline which I don't want to happen here, but /m will treat the single string as multiple lines and /g will let me match more than once before quitting.