# Stuck value check for my $index (0 .. $#data - 5) { my $first = $data[$index]; next if grep {$first != $_} @data[$index + 1.. $index + 5]; # Here if a 'stuck' value was found }