in reply to Find and Replace

You are having a scoping issue. When you use my, your variable is lexically scoped to the current block. In your case, that is the if block, and so you $copy variable is out of scope by the time you get to line 25. Instead, your my needs to be at the same level as you usage, which means script level. You could just move the my before the block and initialize within the block, but I think it would be more logical to replace the if block with

unless (-e $ARGV[0]) { print "File does not exist. \n"; exit; } my($copy) = "$ARGV[0].bak"; copy($ARGV[0], $copy) or die "File cannot be copied. \n";

or if (not... if you don't like unless blocks.