I bid you welcome to the wonderful world of regular expressions (aka regexes). More information can be learned about these from perlre. Here's my version:
my $string = q{
this
is
a
sample
text.
all single blank lines will be removed.
all double, triple, or more
blank lines will not
be touched.
};
$string =~
s#\n(\n+)#"\n" x (length($1)>1 ? length($1)+1 : length($1))#eg;
print $string;
__END__
this
is
a
sample
text.
all single blank lines will be removed.
all double, triple, or more
blank lines will not
be touched.