9. File info

Use stat function to obtain information about the file. :

$file_path = '/home/reinier/example.txt';

if (-e $file_path) {
    # Call stat function to get file information
    @file_info = stat($file_path);

    # Extracting information from the returned array
    $file_size = $file_info[7]; # Size of the file in bytes
    $file_permissions = $file_info[2]; # File permissions
    $file_last_access_time = $file_info[8]; # Last access time
    $file_last_modification_time = $file_info[9]; # Last modification time

    # Print out the file information
    print "File Size: $file_size bytes\n";
    printf "File Permissions: %04o\n", $file_permissions & 07777; # Using octal format to display permissions
    print "Last Access Time: ", scalar localtime($file_last_access_time), "\n";
    print "Last Modification Time: ", scalar localtime($file_last_modification_time), "\n";
} else {
    print "File $file_path does not exist.\n";
}
Easy to make a one-liner. Example:

$ perl -e '$file="example.txt"; (-e $file) ? (@file_info = stat($file), print("Last Access Time: ", scalar localtime($file_info[8]))) : print("$file does not exist!");';