There are numerous modules to do permutations. List-Permutor may fit the bill. E.g.
#! /usr/bin/perl -w
use strict;
use List::Permutor;
my @data = qw / A B C D /;
my $perms = new List::Permutor @data;
while (my @set = $perms->next) {
print "@set\n";
}