use Modern::Perl; my @same = (8) x 8; # an array of eight 8s my @notSame = qw/ 10 10 10 12 10 10 /; say "The array's elements are" . ( sameArrayElements(@same) ? '' : ' not' ) . ' the same.'; sub sameArrayElements { my %hash = map { $_ => 1 } @_; keys %hash == 1 ? 1 : 0; } #### The array's elements are the same.