http://www.perlmonks.org?node_id=891674


in reply to arrays and loop through array

You could use eval, as follows:

#!/usr/bin/perl use warnings; use strict; my $str = "1, 2 ,3, 4,6 -10,11 - 15,16, 17"; $str =~ s/\s+//g; $str =~ s/-/\.\./g; my @arr = eval $str; for (@arr){ my $i = $_; print "==>>> $i\n"; }

You need to be very sure that you have cleaned up arbitrary user input before using eval in this way.