in reply to To find the no of occurenaces and max min value

Use a hash of arrays to save the SQL statements and their running times, then use standard routines from List::Util to compute all the data you need (in other words, don't reinvent the wheel):

#!/usr/bin/perl use feature qw/say/; use strict; use warnings; use List::Util qw/min max reduce/; my %results = (); while(<>) { chomp; my ($sql, $time) = m/^SQL :: (.*), Time Taken :: (\d+)$/; push @{ $results{$sql} }, $time; } foreach(sort keys %results) { my $occ = scalar @{ $results{$_} }; my $min = min @{ $results{$_} }; my $max = max @{ $results{$_} }; my $tot = reduce { $a + $b } 0, @{ $results{$_} }; say "$_ $occ $min $max $tot"; }

This outputs:

$ perl test.pl select * from emp ...etc 2 5 30 35 select * from home ...etc 2 20 20 40 select * from person ...etc 3 10 50 90 $

P.S. I see that you crossposted your question to Stack Overflow. It is generally considered polite to inform people of this to avoid duplicated effort.