use PDL; sub is_a_set { all (($_[0] + $_[1] + $_[2]) % 3) == 0; } sub third_card { (pdl(3,3,3,3)-$_[0]-$_[1]) % 3; } my $X = pdl(0,1,2,2); my $Y = pdl(0,2,2,1); my $Z = pdl(0,0,2,0); if (is_a_set($X, $Y, $Z)) { print "$X, $Y and $Z form a set\n"; } else { print "$X, $Y and $Z do not form a set\n"; } print "To form a set with $X and $Y you need: ", third_card($X, $Y), "\n";