in reply to seaching for replacement
while (my $line = <INFILE>) { my @words; while ($line =~ /\S+/g) { push @words, lc $1; } for my $word (@words) { if (exists $dict{$word}) { $line =~ s/$word/$dict{$word}/gi } } print $line; }
Update: To resolve your dash issue, you could use a character class and quotemeta as follows:
my ( $key, $val ) = /^(\d+)\s+([\w-]+)/; ... my $pattern = quotemeta "\b([$cc]{$min,$max})\b/";
Update: Fixed 1st regex thanks to AnomalousMonk
|
|---|