Perl resize all images

This Perl-Script resize all images to the size 166×125, I used to speed up my homepage:

#!/usr/bin/perl
opendir(DIR, "./");
@files =  grep { /\.jpg$|\.gif$/io } readdir(DIR);
sleep(10);
$count=0;
for(@files){
print "".(($count*100)/$#files)."% ".$_." - ";
$cach = 'convert "./'.$_.'" -print "%wx%h" /dev/null';
$size = `$cach`;
$size =~ /^(.+)x(.+)$/o;
print " - ".$1.":".$2;
if(defined($1) && defined($2) && ($1 > 166 || $2 > 125)){
system('mogrify -resize 166x125 "./'.$_.'"');
}
++$count;
print $/;
}
closedir(DIR);