use Data::Dumper; # Two strings, single blanc, two strings, double blanc my @words=("abcd","efgh", "", "jklm","nopq", "", ""); my $combined; my @combinations; for my $word (@words){ if ($word){ $combined .=$word; } else{ push @combinations, $combined if $combined; $combined=""; } } @words=@combinations; print Dumper\@words;