use strict; use warnings; my @reps; push @reps,{from=>'ZZZ',to=>'456AAA456'}; push @reps,{from=>'AAA',to=>'AAA123'}; push @reps,{from=>'BBB',to=>'XYZ999'}; push @reps,{from=>'DEF',to=>'ANYOTHER'}; while (my $line=) { chomp $line; for my $rep (@reps){ my $from=$rep->{from}; my $to =$rep->{to}; $line=~s/\Q$from\E/$to/g; } # rep print $line."\n"; } # line __DATA__ AAAA more stuff stuff BBB again DEF stuff |ZZZZ| not as simple as it seems