$ perl -le' my $string1 = q[//depot/Efp/Celox/CELOX-3.5.0/CeloxStart.sln]; my $string2 = q[//depot/Efp/Celox/MAIN/CeloxStart.sln]; my $pre = length( ( ( $string1 ^ $string2 ) =~ /^(\0*)/ )[ 0 ] ); my $post = length( ( ( reverse( $string1 ) ^ reverse( $string2 ) ) =~ /^(\0*)/ )[ 0 ] ); print for substr( $string1, $pre, -$post ), substr( $string2, $pre, -$post ) ' CELOX-3.5.0 MAIN