# Takes a number and a list of elements. Returns all possible ways to # select that number out of the list. sub choose_m { my $m = shift; # Special cases first if (0 == $m) { return []; } elsif (@_ < $m) { return (); } else { # This is our recursion step my $first = shift; return ( # Things without the first element choose_m($m, @_), # Things with the first element map {[$first, @$_]} choose_m($m - 1, @_) ); } }