#! perl -slw use strict; sub common { die 'Bad args' unless @_ == 2; my $output = $_[ 0 ] ^ $_[ 1 ]; $output =~ s[([^\0]+|[\0]+)]{ my $p = $-[0]; my $l = $+[0] - $-[ 0 ]; ord( $1 ) == 0 ? substr( $_[ 0 ], $p, $l ) : join '', map{ '[' . substr( $_, $p, $l ) . ']' } @_ }ge; return $output; } while( my $str1 = ) { my $str2 = ; print common( $str1, $str2 ); } __END__ a11211b123 a11222b123 The quick brown fox jumps over the lazy dog the quiet green fir looms over the lazy dog Send reinforcements; we're going to advance Send 3 and sixpence; we're going to a dance Time flies like an arrow Dung flies like a brick