for my $position (0..(length($reference_str)-length($small_str))) { my $processed_str = $small_str ^ substr($reference_str, $position, length($small_str)); next unless $processed_str =~ m<( \0{9} | \0{1} . \0{8,} | \0{2} . \0{7,} | \0{3} . \0{6,} | \0{4} . \0{5,} | \0{5} . \0{4,} | \0{6} . \0{3,} | \0{7} . \0{2,} | \0{8} . \0{1,} )>xms; print("Match found! ", substr($reference_str, $position+pos($processed_str),length($1))) and last; }