Logical error

I have this script to uvscan-update. Seems like that i am getting logical error at the end of the script. It is updating the script and also giving the error message to update it manually. I have deleted the DAT files to see if it will create new and it does. Below is the error and the script:
error:
/bin# ./update-uvscan.pl
Currently installed version:
Version on ftp://ftp.mcafee.com/pub/antivirus/datfiles/4.x: 5945
Updating virus data files...
Download complete...updating now
mv legal.txt /usr/local/uvscan/legal.txt
mv avvclean.dat /usr/local/uvscan/avvclean.dat
mv avvnames.dat /usr/local/uvscan/avvnames.dat
mv avvscan.dat /usr/local/uvscan/avvscan.dat
Error in installation, please install manually
Cleaning up

Script:

#!/usr/bin/perl -w
# uvscan virus DAT file updater written by
# edit by makhan
# 04072010
#
# Net::FTP is required for operation
# and 'tar' should be in the PATH
use strict;
# Set to the directory uvscan is located/installed in.
my $uvscan_directory = "/usr/local/uvscan";
# Set to the temporary directory to download
# the DAT archive.
my $tempdir = "/tmp/dat-updates";
# Set to e-mail address for anonymous FTP login
#my $emailaddress = "makhan";
my $emailaddress = "anonymous";
use Net::FTP;
# Define global variables
my ($ftp, @dirlist, $arraywalk, $localver, $serverver, $localfile,
@files, $file);
# Get the local uvscan datfile version
$localver = &checkuvscanver;
print "Currently installed version: ".$localver."\n";
# Create FTP connection
$ftp = Net::FTP->new("ftp.nai.com", Debug => 0);
# Login
#$ftp->login("anonymous","$Password");
#$ftp->login("anonymous",$emailaddress);
$ftp->login("anonymous",$emailaddress);
$ftp->cwd("/pub/antivirus/datfiles/4.x");
$ftp->binary();
@dirlist = $ftp->ls();
foreach $arraywalk (@dirlist) {
if ($arraywalk =~ /dat-([0-9]+)\.tar/i) {
$serverver = $1;
print "Version on ftp://ftp.mcafee.com/pub/antivirus/datfiles/4.x: ".$serverver."\n";
if ($serverver > $localver) {
print "Updating virus data files...\n";
# Create and then change the working directory to $tempdir
if (!(-d $tempdir)) {
mkdir($tempdir, 700) or die("ERROR: Couldn't make temporary
directory: $tempdir");
}
chdir $tempdir or die("ERROR: Couldn't change directory to tempdir:
$tempdir");
# Download the DAT file!
$localfile = $ftp->get($arraywalk);
print "Download complete...updating now\n";
# Untar the files, store the names of them into an array
@files = `tar -xvf $arraywalk`;
foreach $file (@files) {
# A line break is at the end of each $file...
# chomp that off
chomp($file);
# Move each file to the uvscan_directory;
# and make sure they are lowercase.
my $movestring = "mv $file ".$uvscan_directory."/".lc($file);
print " ".$movestring."\n";
system($movestring);
}
# Make sure that the installation worked,
# by checking if the virus scanner reports
# the same data file version as the one we downloaded.
if (&checkuvscanver eq $serverver) {
print "Installation successful\n";
} else {
#print "Error in installation, please install manually\n";
}
# Cleanup...
print "Cleaning up\n";
# Remove downloaded DAT archive
unlink($arraywalk) or die("ERROR: Couldn't delete DAT file:
$arraywalk");
# Change to filesys root
# and remove temporary directory
chdir("/");
rmdir($tempdir) or die("ERROR: Couldn't remove tempdir: $tempdir");
} else {
#
if ($serverver < $localver) {
print "DAT files are the same..no need to update\n";
}
# Don't want to continue if there is more than
# one 'dat-[0-9]+.tar' files
last;
}
}

#$ftp->quit;
# uvscan --version reports...
# "Virus data file 4229 created Oct 16 2002"
# &checkuvscanver returns the version
# of the data files.
sub checkuvscanver {
if (`$uvscan_directory/uvscan --version` =~ /Virus data file
v([0-9]+) created/) {
return $1;
}
}
}

You really should indent your code and not use cuddled else - } else { and so on.
I actually have trouble reading your code. Maybe a major perler can deal with it - I am a minor perler.