http://www.perlmonks.org?node_id=1008310


in reply to Removing blank/empty lines

Use a regex like /$\s*^/ to anchor the pattern at both ends and search for zero-or-more occurrences of a space character between.