#!/usr/bin/perl -w use strict; my @data; # define a hash of changes to be made my %change = ( HEAL => 'NOTE Medical:', HIST => 'NOTE Biography:', EDUC => 'NOTE Educated:', RESI => 'NOTE Resided:', OCCU => 'NOTE Occupation:', ); # accept input via three mechanisms # if no file specified here: my $file = ''; # then look for a command line argument here: $file = shift @ARGV unless $file; # if we still have no file to process # enter interactive mode here: unless ($file) { print "Please enter a file to process: "; chomp($file = <>); } # get the data open (FILE, "<$file") or die "Unable to open $file: $!"; @data = ; close FILE; # make the changes for (@data) { for my $key (keys %change) { s/$key/$change{$key}/g; } } # print the changes to a new file with the same name # as the original plus a .new suffix. open (FILE, ">$file.new") or die "Unable to write $file.new: $!"; print FILE @data; close FILE; print "Munged $file no worries!\n";