in reply to arrays and loop through array

Replacing

$str =~ s/-/\.\./g;
by
$str =~ s/(\d+)-(\d+)/join(",",$1..$2)/ge;
seems to do what you want... (on correct input: positive numbers, first one lesser than second).