#!/usr/bin/perl use strict; no warnings; foreach my $in (@ARGV){ my($copy) = "$in.bak"; copy($in, $copy) or die "File cannot be copied. \n"; open(INPUT,"$copy") or die 'Cannot open file: $!\n'; open(OUTPUT,">$in"); my($replacePattern1) = "foo1"; ... }