String::MMM - Perl XS for comparing (matching) strings MasterMind style


  use String::MMM qw(:all);
  my @result = match_strings( 'AAAA', 'ABCD', 6 ); # 6 is alphabet size;
  # $result[0] contains number of blacks, $result[1] whites
  @result = match_strings_a( 'abcd', 'efgh' ); # alphabet size = 26;
  # should return 0,0
  @result = match_arrays( [ 0,3,2,1], [0,0,1,2], 10 );


String comparison is a critical operation in MasterMind, and the fastest Perl implementation is not fast enough. This implementation can be up to an order of magnitude faster (depending on string size, of course).


match_strings ( $hidden, $target, $colors )

Matches 'A'-based strings (from 'A....A' to 'chr($colors)...chr($colors)', with an alphabet of size $colors. Returns an array with the number of blacks and whites as first and second element. Length is not checked; comparison is done over the length of $hidden.

s_match_strings ( $hidden, $target, $colors )

Matches 'A'-based strings (from 'A....A' to 'chr($colors)...chr($colors)', with an alphabet of size $colors. Returns a string with "%db%dw" as format. It happens that it's useful that way and slow to do it otherwise

match_strings_a ( $hidden, $target )

Same as above, with lowercase letters. Besides, $colors is assumed to be 26.

match_arrays ( $ref_to_hidden_array, $ref_to_target_array, $colors )

Same as above, with integer numbers. Just in case you need more than 26 symbols. Why would you? Nobody knows. But I don't want to pull a Bill Gates here.


This module is used by some algorithms in Algorithm::MasterMind.


Needs a C compiler to install.


This project is hosted at GitHub. You can send bug reports to the issue tracker o or the CPAN tracker. Please use the CPAN forum for discussion, comments and feature requests.


Juan J. Merelo Guervós, <>


Copyright (C) 2013 by Juan J. Merelo Guervós

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.0 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 96:

Non-ASCII character seen before =encoding in 'Guervós,'. Assuming UTF-8