use strict; use warnings; my %hash; open my $fh, '<', 'abc.txt' or die $!; while (<$fh>) { chomp; my ($key, $val) = split '\|'; $hash{$val}++; } print "$_\n" for sort keys %hash;