A simple permutation program is listed below. It permutes all the array elements given.

sub Permute {
	my ($arrayref, $currentindex) = @_;
	my $elementcount = scalar @{$arrayref};
	
	if($currentindex == $elementcount) {
		foreach (@FOUND) { print $arrayref->[$_].' '; }
		print "\n";
		return;
		}
	
	for(my $i=0; $i<$elementcount; $i++) {
		next if $USED[$i] == 1;
		$USED[$i] = 1;
		$FOUND[$currentindex] = $i;
		Permute($arrayref, $currentindex+1);
		$USED[$i] = 0;
		}
	}
	

my @USED = ();
my @FOUND = ();


my @A = ('aaa', 2, 4, 'z');
Permute(\@A, 0);