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;