line-endings detection I would like to detect which is the line-endings type of a file. I wrote this function: 

 open my $fh, '&lt;afile.txt';
 seteol($fh);


Here the eol detection subroutine: 

 sub seteol {
    my $fh = shift;
    my $byte;
    my $i = 0;
    while (sysread($fh, $byte, 1)) {    
        if($byte eq "\n") {
            $/ = "\n";                
            return 0;
        }
        elsif($byte eq "\r") {
            sysread($fh, $byte, 1);
            if($byte eq "\n") {
                $/ = "\r\n";
                return 0;
            } else {
                $/ = "\r";
                return 0;
            }
        }
        last if $i++ &gt; 65535;
    }
    return -1;
    seek($fh,0,0);     
}


I am wondering if I can do a better job with only core-modules.
It reads file by 4096 chars in hope to find EOL,

local $/ = seteol($fh) // $/;

sub seteol {
    my $fh = shift;

    local $/ = \4096;
    my $line = "";

    while (my $b = &lt;$fh&gt;) {        
      $line .= $b;
      last if $line =~ /(\R)/;
    }
    seek($fh,0,0);
    return $1 if $1;

    warn "Unknown EOL";
    return;
}