in reply to trim the blank lines...regex

In an arch-typical file-processing loop (such as the ones described in, ummm, the multitudinous perlfaqs...), the usual procedure is to use chomp to remove any newlines, then use a regular-expression to eliminate unwanted lines. Then output the ones that pass, remembering to include the record-separator.

For such a trivial task as this, the grep command-line tool might already be exactly what you need.

Otherwise, your regular expression is probably going to be something like: /^\s*$/ which breaks-down as follows:

As I previously mentioned, you can probably do the entire job with the grep command, using the "-v" modifier to invert the meaning of the pattern:   all lines which do not match the pattern will be output. This omits the blank lines (which are the ones that match) and outputs the non-blanks. Q.E.D.

(An equivalent Perl program could of-course be constructed, but since this is trivial ...)