Hi , I have a file which have input as like below pet="cat"|hate="rat"|like="dog" hate="rat"|like="dog"|pet="cat" hate="rat"|like="horse"|pet="cat" pet="cow"|hate="rat"|like="dog" hate="rat"|like="dog"|pet="cow" And output im looking is pet="cat"|hate="rat"|like="dog" pet="cow"|hate="rat"|like="dog" Any first instance where I find unique value for pet and hate I wanted to print. Thanks #### #! /usr/bin/env perl use strict; use warnings; my %pet_hate; while (<>) { my ($pet) = /pet="(\w+)"/ or next; my ($hate) = /hate="(\w+)"/ or next; my ($like) = /like="(\w+)"/ or next; $pet_hate{"$pet:$hate"} //= { pet => $pet, hate => $hate, like => $like, }; } foreach (values %pet_hate) { printf(qq{pet="%s"|hate="%s"|like="%s"\n}, $_->{pet}, $_->{hate}, $_->{like}); }