#!/usr/bin/perl use strict; my @animals = ( "bear<1>\n", "camel<0> <2>\n", "<2>horse\n", "duck<3>\n" ); my %changemap = ( "<0>" => 'A', "<1>" => 'B', "<2>" => 'C', "<3>" => 'D', ); # build a single regular expression to match all of the # items we're changing from my $from = join '|', keys %changemap; for (@animals) { s/($from)/$changemap{$1}/g; } print @animals; __END__