#!/usr/bin/perl -w my @Times = (1,2,3,4,7,8,9,12,14,15,19,20,21,22,23); my $index = 0; my @v; while ( $index <= $#Times ) { $t = $Times[$index]; push @v, $t; last if $index == $#Times; $count = 0; foreach $k ( @Times[ $index + 1 .. $#Times] ) { printf "I: %2d T: %2d C: %2d K: %2d\n", $index,$t,$count,$k; if ( $t + $count + 1 == $k ) { $count++; } else { last; } } if ( $count >= 2 ) { $index += $count; push @v, ("-", $Times[ $index ] ); } $index++; } print "Original: ", join(",",@Times), "\n"; $str = join(",",@v); print "Consolidated: $str\n"; my $formatted = $str; $formatted =~ s/,-,/-/g; print "Formatted: $formatted\n"; my $fmttime = $formatted; $fmttime =~ s/(\d+)/sprintf("%d%sm",($1>12?$1-12:($1==0?"12":$1)), ($1<12?"a":"p"))/eg; print "Time Fmt: $fmttime\n";