while () { chomp; last if !$_; # or other suitable termination test $header .= "$_\n"; }