my $xor = $file1contents ^ $file2contents; my $max = 0; my $max_str; my $pos; while ($xor =~ /(\0+)/g) { my $len = length $1; if ($len > $max) { $max = $len; $max_str = substr $file1contents, $-[0], $len; $pos = $-[0]; } #print "matched $-[0] ", substr $file1contents, $-[0], $+[0] - $-[0]; } print "at pos $pos max string is $max_str";