use strict; use warnings; open(my $fh1, '<', $ARGV[0]) or die $!; binmode($fh1); open(my $fh2, '<', $ARGV[1]) or die $!; binmode($fh2); for (;;) { defined(read($fh1, my $buf1='', 4096)) or die $!; defined(read($fh2, my $buf2='', 4096)) or die $!; if ($buf1 ne $buf2) { print("Different\n"); exit(1); } last if !length($buf1); } print("Same\n"); exit(0);