%hash = ( America => 'country', France => 'country', 'George Bush' => 'name', ); #### %hash = ( country => [ 'USA', 'France', 'Austria', 'Israel'], name => [ 'Georg Bush', 'Marie LePen', 'Jörg Haider', 'Ehud Olmert'], ... ); #### while (defined(my $line = )) { # read one line into $line while(my($repl,$ary) = each %hash) { # iterate over %hash foreach my $token(@$ary) { # @$ary: dereference the array in $ary $text =~ s/$token/<$repl>/g; # substitute each token with hash key } } print $line; # done }