use strict; print "Enter characters to permutate : "; $_ = ; s/\s+//g; split(//); my ($last, $chars); foreach (sort @_) { if ($_ ne $last) { $chars .= $_; $last = $_; } } for ($_ = length($chars); $_; $_--) { permutate($_, $chars); } sub permutate { my ($depth, $chars, $pre) = @_; if ($depth == 1) { print $pre.substr($chars,$_,1)."\n" for (0..(length($chars)-1)); } else { for (0..(length($chars)-$depth)) { permutate($depth-1, substr($chars,$_+1), $pre.substr($chars,$_,1)); } } }