in reply to How to add the rows by its similar row names using perl?

G'day gopikavi,

Welcome to the Monastery.

I see ++huck has pointed out your indexing error and usage of a hash. Here's an alternative method for capturing the data:

#!/usr/bin/env perl -l use strict; use warnings; my %slot; my $re = qr{([a-z]{3}).*?(\d+)/(\d+)}; while (<DATA>) { if (/$re/) { $slot{$1}{used} += $2; $slot{$1}{free} += $3; } } print "$_: @{$slot{$_}}{qw{used free}}" for sort keys %slot; __DATA__ {asf192lin1 C 0/8 0 0 0 4503 16 2922 44316 1} {asf256lin10 + 2/16 15 0 0 4641 16 2926 194108 0} {cad192lin1 C 0/12 2 0 0 1432 12 3397 179605 0} {cas256lin1 C 0/12 50 0 56 3992 12 3397 165099 0} {cas192lin11 C 0/12 50 0 56 3992 12 3397 165099 0} {dsf192lin6 + 0/16 0 0 0 4751 16 2930 179123 0}

Output:

asf: 2 24 cad: 0 12 cas: 0 24 dsf: 0 16

— Ken