{ # For the sake of the example, this assumes that you # want to limit the possible input to this range print "Please enter a number [1-9999]: "; chomp($in = ); redo unless $in =~ /^\d+$/ && $in > 0 && $in <= 9999; } print join(",", 1 .. $in), "\n";