#!/usr/bin/perl -w use strict; sub RunLengthEncode { my @out; while( @_ ) { my $next= shift; if( ! ref($next) ) { $next= {count=>1,value=>$next}; } if( @out && $out[$#out]{value} eq $next->{value} ) { $out[$#out]{count} += $next->{count}; } else { push @out, $next; } } return @out; } for( @ARGV ) { print join ",", map { $_->{count}."*".$_->{value} } RunLengthEncode( split /,/, $_ ); print $/; }