in reply to uninitialized value $_
In addition to what Corion has imparted; once you understand what was causing the error - here is a one-liner you may use that echoes input to filename.txt and stops when a blank line is entered:
perl -pe "last if /^\s*$/" > filename.txt
|
|---|