use strict; use warnings; my @goodarray = ( 1, 1, 1, 1, 1 ); my @badarray = ( 1, 2, 3, 4, 5 ); foreach my $aref ( \@goodarray, \@badarray ) { print SameVals($aref) ? "Good!\n" : "Bad!\n"; } sub SameVals { keys %{ { map { $_ => undef } @{ +shift } } } <= 1; }