#!/usr/bin/perl -s use v5.16; use Test2::V0; use experimental 'postderef'; our $examples; run_examples() if $examples; # does not return say(<[0]}->@*, $_->[1] foreach map {[join('', sort split //), $_]} @_; # Sort the canonical anagrams and retrieve the corresponding string # lists. (The sort is required for a stable result only.) map {$anagroup{$_}} sort keys %anagroup; } sub run_examples { is [anagroup qw(opt bat saw tab pot top was)], [[qw(bat tab)], [qw(saw was)], [qw(opt pot top)]], 'Example 1'; is [anagroup 'x'], [['x']], 'Example 2'; done_testing; exit; }