#!/usr/bin/perl # http://perlmonks.org/?node_id=1212142 use strict; use warnings; my %cats = ( blackcat=>5, whitecat=>10,orangecat=>20 ); while() { print; s#([a-zA-Z][A-Za-z_0-9]+)# $cats{$1} // $1 #ge; print; } __DATA__ log10(blackcat)*whitecat*(log10(orangecat)) #### log10(blackcat)*whitecat*(log10(orangecat)) log10(5)*10*(log10(20))