in reply to parsing and get the report

Trying to account for all the quirks of the calendar is very tricky business. That is why there are so many CPAN modules which will do this for you, Date::Calc, for example. You should seriously consider replacing your find_diff sub with something tried and tested from CPAN.

use warnings; use strict;

Check the success of open, use its 3-argument form and use lexical filehandles, $fh:

open my $fh, '<', $File or die "can not open $File: $!"; while (<$fh>) { ... } close $fh;

This:

if ( $_ =~ /([0-9]+\:[0-9]+\:[0-9]+) ([0-9]+) (\w+) (\w+) (\w+)/ ){

is more concisely written as this:

if (/(\d+:\d+:\d+) (\d+) (\w+) (\w+) (\w+)/ ){

Update: OK, I'm back in from shoveling snow. You should choose a better name for your hash data structure than %hash. I dont think you need all those extra variables, just stuff them into your hash right away.

use strict; use warnings; my %hash; my $File = "input.txt"; open my $fh, '<', $File or die "can not open $File: $!"; while (<$fh>) { chomp; ## taking time, transaction id, status, transaction name and amoun +t. if (/(\d+:\d+:\d+) (\d+) (\w+) (\w+) (\w+)/ ){ $hash{$2} = [($3, $1, $4, $5)]; } ## If the status is stop.. elsif (/(\d+:\d+:\d+) (\d+) (\w)/ ) { $hash{$2}->[0] = $3; my $difftime = find_diff($hash{$2}->[1], $1); $hash{$2}->[1] = $difftime; print "Transaction id $2 name $hash{$2}->[2] Amount $hash{$2}- +>[3] Duration $hash{$2}->[1]\n"; # If the transaction is stopped initialising the values. delete $hash{$2}; } } close $fh; print "============================================\n"; ## to print the transaction started but not yet stopped for my $id ( keys %hash ) { if ( $hash{$id}->[0] =~ /start/i ) { print "Transaction with id $id is started but not yet stopped\ +n"; } }