# If I were doing this as part of a production piece, and # I figured it would be reused and extended and so forth, # I'd probably write a little sub to spit out a comma- # separated list of integers, and regex it into the # original sentence. But I don't think you need that # complexity. if (working_sentence =~ /#\d+#/) { # now we take an Array Slice* from the array of numbers # we got from file. We use $1 from the preceding regex # because... well, because we can. my @working_numbers = @numbers[0..$1-1]; # remove that slice from the numbers array delete @numbers[0..$1-1]; # join the numbers into a comma-separated list my $number_list = join ', ', @working_numbers; # and insert it into the original sentence $working_sentence =~ /#\d+/$number_list/; }