use strict; use warnings; my @words = qw(book reboot rocket); my @chars = map {[split '']} @words; my %matches; for my $row (0 .. $#chars) { for my $column (0 .. $#{$chars[$row]}) { push @{$matches{$chars[$row][$column]}}, [$row, $column]; } } for my $char (sort keys %matches) { next unless @{$matches{$char}} > 1; print "$char=", join (',', @$_), "\n" for @{$matches{$char}}; }