# This script was excerpted from http://stackoverflow.com/questions/11678939/replace-text-based-on-a-dictionary use strict; use warnings; use Text::CSV; open my $fh, '<', 'kegg_pathway_title.txt' or die $!; my %dict = map { chomp; split ' ', $_, 2 } <$fh>; my $re = join '|', keys %dict; open $fh, '<', 'Orthogroups_3.csv' or die $!; while (<$fh>) { next if $. < 2; s/($re)/$dict{$1}/g; print; }