my $string = q{ 1. This is just a sample. 2. This is to check 3. How a set of values 4. can be replaced by another 5. set of values and that too 6. in the most efficient way. }; my %replacements = ( '1.' => 'a.', '2.' => 'b.', '3.' => 'c.', '4.' => 'd.', '5.' => 'e.', '6.' => 'f.', ); my $regexp = join '|', map quotemeta, keys %replacements; $string =~ s/($regexp)/$replacements{$1}/g; print $string;