sub permute { return if $_[0] && $_[0] / length($_[0]) != int ($_[0] / length($_[0])); if (!length($_[1])) { print $_[0]." "; return; } for (0..length($_[1])-1) { permute($_[0].substr($_[1],$_,1), substr($_[1],0,$_).substr($_[1],$_+1)); } }