use File::stat; open( my $FH, "<", $fileOrPipeOrWhatever ) or die $!; my $fileSize = 0; my $blockSize = stat($FH)->blksize; my $len; while($len = sysread($FH, my $buf, $blockSize) ) { $fileSize += $len; } # while die $! unless defined $len; close( $FH );