#!/usr/bin/perl -w use strict; # For brevity, there is no error checking here. # In Real Life[TM], you should, of course, check for errors. my %TranslationTable = (); # Load Translation Table { open TRANSLATION_FILE, ") { chomp $trnbuf; my ($currentVariableName, $newVariableName, @garbageData) = split /\:/, $trnbuf; $TranslationTable{$currentVariableName} = $newVariableName; } close TRANSLATION_FILE; } # Non-destructively modify files specified on command line foreach my $inputFilename (@ARGV) { my $outputFilename = $inputFilename . "-NEW.COB"; open INPUT_FILE, "<$inputFilename"; open OUTPUT_FILE, ">$outputFilename"; while (my $inputBuffer = ) { my $outputBuffer = $inputBuffer; foreach my $currentVariableName (keys %TranslationTable) { my $newVariableName = $TranslationTable{$currentVariableName}; # Your logic will likely be more intense here # For example, how to confirm you are only modifying variable references? my $translationRegex = quotemeta $currentVariableName; $outputBuffer =~ s/$translationRegex/$newVariableName/ig; } print OUTPUT_FILE $outputBuffer; } close INPUT_FILE; close OUTPUT_FILE; } exit; __END__