use warnings; use strict; my $filename = '/tmp/input.txt'; open my $fh, '<:encoding(UTF-8)', $filename or die "$filename: $!"; my %seen; while (<$fh>) { chomp; my @fields = split /,/; $seen{$fields[1]}++ } close $fh; my @data = sort keys %seen; print $_,"\n" for @data;