@_ = qw (opt pot top stoop stop pit ipt); #### opst counted 1 times oopst counted 1 times opt counted 3 times ipt counted 2 times #### use strict; my %h; @_ = qw (opt pot top stoop stop pit ipt); for ( @_ ) { my $last; $h{join "", grep { if ( $_ eq $last ) { "" } else { $last = $_; $_ } } sort split "", $_}++; } for ( keys %h ) { print "$_ counted $h{$_} times\n"; } #### opst counted 2 times opt counted 3 times ipt counted 2 times