Let's say you're given "1,3-5,7" and you need to set a value in each of those indices in some array. You can't just eval that string as its not valid Perl.

This snippet as written will set each index in the range to true, leaving all others as undef, or false.

my @stuff; my $vals = "1,3-5,7"; $vals =~ s/(\d+)-(\d+)/join ',', $1..$2/eg; # If you need to convert to 0-based ... $vals =~ s/(\d+)/$1 - 1/eg; my $numIndices = scalar split ',', $vals; eval "\@stuff[$vals] = (1) x $numIndices;";