#!/usr/bin/perl -wT use strict; use utf8; my @hand = ('k of hearts', 'k of diamonds', 'j of spades', 'j of hearts'); my $same_kind=0; my $same_color = 0; for ( my $i=0; $i<$#hand+1; $i++) { for ( my $j=$i+1; $j<$#hand+1; $j++) { my (@first) = split(" of ", $hand[$i]); my (@second) = split(" of ", $hand[$j]); print "Split1: $first[0]\n"; print "Split2: $second[0]\n"; if ( $first[0] eq $second[0] ) { #pair $same_kind +=1; } elsif ( $first[$#first] eq $second[$#second] ) { $same_color +=1; } } } print "You have same kind of cards: $same_kind\nand $same_color of same color.\n";