# Then control the output foreach $index (@array){ # if the line is completely blank dont print it. if ($index !~ /^\s*\n\s*$/) { print "$index"; } }