#!/usr/bin/perl use strict; use warnings; my $f1Data = <)) { chomp $line; my ($tagId, $value) = split ',', $line; next if ! defined $value; $lu{$value}{tagid} = $tagId; } open my $f2In, '<', \$f2Data; while (defined (my $line = <$f2In>)) { chomp $line; my ($key, $label, $value) = split ',', $line; next if ! defined $value || !exists $lu{$key}; $lu{$key}{children} .= <$label $value CHILD } for my $key (sort keys %lu) { print < $lu{$key}{children} PARENT } #### ABC 10 PQR 34 XYZ 37 LMN 14