sub common { if ( $_[0] eq $_[1] ) { return( $_[0], "", "" ); } else { use bytes; my ( $pos, $len0, $len1 ) = ( 0, length($_[0]), length($_[1]) ); # find the offset of the first byte that differs while ( vec($_[0], $pos, 8) == vec($_[1], $pos, 8) ) { $pos++; last unless ( $pos < $len0 && $pos < $len1 ); } return( unpack("a${pos}", $_[0]), unpack("x${pos}a*", $_[0]), unpack("x${pos}a*", $_[1]), ); } }