$s1 = "45 20 00 00 00 03 00"; $s2 = "40 20 00 00 00 00 00"; while ((@a = $s1 =~ /(\d{2})/g) && (@b = $s2 =~ /(\d{2})/g)){ print "found $a[0] and $b[0] !!!\n"; }