in reply to trim the blank lines...regex
Perhaps a hangup here is that s/^$// will match a blank line but will not remove the ending newline since $ doesn't include the newline.