Though I haven't tested to see if this script works, it might be along the lines of what I have written below. However instead of checking which files exist in temp and not in live then I suggest that the find and replace code isn't the most practical...
Instead maybe use something like this...
unless (grep @log1 eq $_, @log2)
Here is my code anyways...
#! /usr/bin/perl
use strict;
use CGI ':standard';
#################################################
## Open TEMP directory AND open LIVE directory ##
#################################################
opendir (LOGDIR, "Path_To_Temp_Directory") || Error ('open', 'directory');
my @log1 = readdir (LOGDIR);
closedir (LOGDIR);
opendir (LOGDIR, "Path_To_Live_Directory") || Error ('open', 'directory');
my @log2 = readdir (LOGDIR);
closedir (LOGDIR);
##############################################################
## Check which files do not exist within the LIVE directory ##
##############################################################
@log1 =~ s/@log2//;
###################################################################
## Delete the files which do not exist within the LIVE directory ##
###################################################################
unlink ("Path_To_Temp_Directory/@log1") || Error('delete', 'file');
#####################################################
## Use copy module to move files from LIVE to TEMP ##
#####################################################
$templocation = "Location_Of_Temp_Directory";
$livelocation = "Location_Of_Live_Directory";
use File::Copy;
move($livelocation, $templocation);
#########
## END ##
#########