in reply to How can I keep the first occurrence from duplicated strings?

Using hash with //=

#!/usr/bin/perl use strict; # https://www.perlmonks.org/?node_id=11154123 use warnings; open my $fh, '<', \<<END or die; nick 5 nick 10 nick 20 john 78 erik 9 erik 12 END my %hash; $hash{ (split)[0] } //= $_ while <$fh>; print values %hash;

Outputs(order varies by run because of perl's hash randomizing):

nick 5 erik 9 john 78