my $buf = ''; ...; while (<$input>) { ...; $buf .= $newletter; }