#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my $length = 2; my @motif = ( '' ); for my $i ( 1 .. $length ) { @motif = map { my $motif = $_; map $motif . $_, qw( a t c g ); } @motif; } print Dumper \@motif;