#!/usr/bin/perl use strict; use warnings; my @array=("abc","1,2,3","T","pu,pr"); my @strings = (shift @array); for my $i ( @array ){ if( index($i, ',') != -1 ){ @strings = map{my $j = $_; map{ $_ . $j }@strings}split /,/, $i; } else{ $_ .= $i for @strings; } } print $_,"\n" for @strings;