use List Util qw[ reduce ]; print 'They\'re all the same!' if reduce{ $a && $a eq $b ? $a : () } values %hash;