#!/usr/bin/perl use warnings; use strict; sub text_to_list { my $a = shift; my @b = split(/,/, $a); my ($i, $u); my (@c, @d); for $i (@b) { if ($i =~ /-/) { @c = split(/-/, $i); for $u ($c[0] .. $c[1]) { push(@d, $u); } next; } push(@d, $i); } return @d; } # (3,6,7,8,9,10,16,23) my $i; my @result = text_to_list("3,6-10,16,23"); for $i (@result) { print "$i\n"; }