while ( $texttosub =~ s/(?!log10)|([a-zA-Z][A-Za-z_0-9]+)/$cats{$1}/i ){ ..do something.. }