#!/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"; ... } #### opendir(DIR, $ARGV[0]) || die "i died for no reason ;)\n"; foreach (readdir DIR){ #repeat like above #watch out for defining the right path to dir and when looping re-type the fool path to your dir, like: # open (FILE, ">", "$ARGV[0]/$_") || die "i died for no reason ;)\n" }