Hi,
I've had a quick play and think something like this would be what you are looking for:
#!/usr/bin/perl
use strict;
my @array = (1,1,1,1,1,1,2,1,1,1,3,3,1,1,1,1,1,2,2,2,3,4,5,8,9,9);
my $consecutiveItems = [];
my $consecutiveHash = {};
my $lastElem = undef;
my $count = 0;
# gather...