#!/usr/bin/perl use strict; use warnings 'all'; use File::stat; # use the object-oriented interface to stat my $file = "rajesh.txt"; my $file_timestamp = stat($file)->mtime; # gets the file-modified time, in # seconds since the epoch # my $startTime = time(); # You don't even really need this -- Perl has a # built-in variable, $^T, that records when your # script started to run. See the perlvar manpage. my $timestamp = localtime($^T); # localtime, with no argument, assumes # localtime(time). My example gets the localtime of $^T. # Assigning this to a scalar variable, as # you do here, gives you the # formatted ctime. You also could # have done localtime(time) here, # or just localtime with no argument. my $rajesh = $^T - $file_timestamp; # This is really all you need to do here. You could # also use the time function to get the current time, # i.e. $rajesh = time - $file_timestamp my $pretty_file_timestamp = localtime($file_timestamp); # Get the scalar (ctime) format print "The current time is = $timestamp\n"; print "The file modified time is = $pretty_file_timestamp\n"; print "The difference between file modified time and current time is = $rajesh\n";