in reply to Algorithm performance enhancement needed

As dragonchild rightly points out, you leave us guessing about the parent-child relationship, but assuming that a "child" is defined as being identical to a parent but with a suffix of /_\w+/, and also assuming that "children" will not appear in the list unless a matching parent also appears in the list, you could start with the following code.

use strict; use warnings; use Data::Dumper; chomp (my @family=<DATA>); my %parents; for (@family) { if (/(Test\d*_\d+(?:\.\d+){3})(_.+)/) { push @{$parents{$1}},$_; } } print Dumper(\%parents); __DATA__ Test_100.26.35.6_1 Test_100.26.35.6_13 Test2_9.25.6.27_2 Test2_9.25.6.27 Test_100.26.35.6 Test_100.26.35.6_10 Test3_28.20.116.210_ide Test3_28.20.116.210 Test4_28.25.6.21_45 Test4_28.25.6.21_45_25

Output:

$VAR1 = { 'Test3_28.20.116.210' => [ 'Test3_28.20.116.210_ide' ], 'Test2_9.25.6.27' => [ 'Test2_9.25.6.27_2' ], 'Test4_28.25.6.21' => [ 'Test4_28.25.6.21_45', 'Test4_28.25.6.21_45_25' ], 'Test_100.26.35.6' => [ 'Test_100.26.35.6_1', 'Test_100.26.35.6_13', 'Test_100.26.35.6_10' ] };