#!perl -an0 map{push@{$s[$j{join"",sort/./g}||=++$i]},$_}sort@F;for$h(2..99){map{print"@$_ "if@$_==$h}@s}