sub fix_special_characters { my($string) = @_; open(C,"<:utf8","chars.txt"); my @c = ; chomp @c; for my $i (0 .. $#c) { my ($special, $htmlchar) = split /\s+/, $c[$i]; print "$special : $htmlchar\n"; $string =~ s/$special/$htmlchar/ig; ## this is generating the error message } return $string; }