use strict; use Data::Dumper; my @words = qw/opt top pot pit tip/; my %count; foreach my $w(@words) { my $key = join '', sort split '', $w; $count{$key}++; } print Dumper \%count; #### $VAR1 = { 'opt' => 3, 'ipt' => 2 };