# File: stringCompare0.pl # Compare 2 strings of same length. Print position of equal char. # For strings: instead of $s[3] you write substr($s,3,1) # 1 - means take one char from position 3. # Author: Mihaela Malita # Compare # aabbcc # aXbXcX # 0*2*4* $s1 = "aabbcc"; # 2 strings $s2 = "aXbXcX"; $len = length($s1) ; # strings have equal length print "Compare\n$s1\n$s2 \n"; foreach $i (0..$len-1){ # loop after index if ( substr($s1,$i,1) eq substr($s2,$i,1) ) {print $i;} # print position where chars are equal else {print '*';} # put * where the chars are not equal } exit;