line-endings detection
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;
}