use strict; use warnings; my $to_split = "'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'"; my @pieces = grep {$_} split /('\w'(?:,'\w'){0,4}),?/, $to_split; $"="\n"; print "@pieces\n";