use strict; use warnings; my @config = qw|this oldtext needs replacement but not newtext Just oldtext|; for (@config) { s/oldtext/newtext/ } print qq|$_;\n| for @config; # "Perl" style print for my $t (0 .. $#config){ # Your style (c-style for loop) print "$t:$config[$t];\n"; }