My updated code that seems to work. Thanks again pvaldes for your help!
pvaldes' code:
while (<>) {
next if $_ =~ m/\n{1}/;
if ($_ =~ m/\n{2}){s/\n{2}/\n/gs}
elsif ($_ =~ m/\n{3,}){s/\n{3,}/\n\s/gs}
}
Mine:
while (<>) {
if ($_ =~ m/\n{1}/) {
}
if ($_ =~ m/\n{2}/){
s/\n{2}/\n/gs;
print;
}
elsif ($_ =~ m/\n{3,}/){
s/\n{3,}/\n/gs;
print;
}
}
Above does not work. Below now works (prob a crude way of doing it. Please reply if you have a more elegant way):
while (<>) {
if ($_ =~ m/\S\n{2}\S/){
s/(\S)\n{2}(\S)/$1\n$2/gs;
print;
}
elsif ($_ =~ m/\n{3,}/){
s/\n{3,}/\n\n/gs;
print;
}
}