# Convert age (in days) to seconds my $maxage = $maxagedays * 3600 * 24; # Convert days to seconds # get the "last modified" timestamp of the file in SECONDS (unix timestamp) my $fileage = stat("$dir/$fname")->mtime; # Current time in seconds (unix timestamp) my $now = time; # Age in seconds my $age = $now - $fileage; # Ignore file if it is too new next if($age <= $maxage); # Add files to the "@todelete" list with full filename push @todelete, "$dir/$fname";