I'm a little afraid of answering this 'cause it looks a bit like homework. That said...
The first question I have is "how did you get the string in the first place?" The answer to this might present a better solution (e.g., don't concatenate blank lines to $str in the firs place).
To answer your original question, though:
use strict; use warnings; use diagnostics; print "START: '$str'"; $str =~ s/\n\n+/\n/g; print "\nEND: '$str'";
In reply to Re: trim the blank lines...regex
by wade
in thread trim the blank lines...regex
by dani_cv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |