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 }