The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
sub _autoflush {
    my $flushed = shift;
    my $old_fh  = select $flushed;
    $| = 1;
    select $old_fh;
}

_autoflush( \*STDOUT );
_autoflush( \*STDERR );

print STDOUT "one\n";
print STDERR "two\n\n";
print STDOUT "three\n";