#!/usr/bin/env perl use strict; use warnings; ### This eval code snippet works ### eval(my $ref2 = "parent_ref"); #################################### my $string = "first_string ref[i] second_string $ref2.ref[i] third_string"; my $new_string; my $i; for ($i=0; $i<5; $i++) { print "$i : "; $new_string = $string; # don't clobber original string, else search-and-replace fails after first loop $new_string =~ s/\[i\]/\[$i\]/g; print "$new_string\n"; }