use strict; use Data::Dumper; my $list = "1-5,6a-e,7,9-12,89xDC-G"; my @s = map { my @t = split /-/; my $l = length($t[0]) - 1; # length less 1 $#t == 0 ? $_ : $t[0] + 0 eq $t[0] ? # pure number? $t[0] .. $t[1] : map { substr($t[0],0,$l) . $_ } substr($t[0],$l,1) .. $t[1] } split /,/, $list; print Dumper(\@s);