DB<122> sub invert { my ($h)=@_; my %h2; while ( my ($k,$v) = each %$h ) { push @{ $h2{$v} } , $k; } return %h2; } DB<123> @t{a..f}=(1,2)x3 => (1, 2, 1, 2, 1, 2) DB<124> \%t => { a => 1, b => 2, c => 1, d => 2, e => 1, f => 2 } DB<125> invert \%t => (1, ["e", "c", "a"], 2, ["b", "d", "f"])