my $string = '1-3 5 8 9-10'; my @array; while ( $string =~ /(\d+(?:-\d+)?)/g ) { my ($start,$ende) = split /-/, $1; if ( $ende ) { push @array, $start .. $ende; } else { push @array, $start; } } print join "::", @array;