for my $idx ( 0 .. 10 ) { my $newstr = $str; $newstr =~ s/\$idx/$idx/; do_something( $newstr ); }