#!/usr/bin/perl -w use strict; print "Enter the name of your file, ie myfile.txt:\n"; chomp(my $val = ); my %seen; open my $fh, '<', $val or die "wrong filename: $!"; while (defined(my $line = readline $fh)){ my @list = split "\t", $line; @seen{@list} = map{$seen{$_}||0+1} @list ; } #while(my($string, $count) = each %seen){ foreach my $key(sort {$seen{$b} <=> $seen{$a}} keys %seen){ my $string = $key; my $count = $seen{$key}; print "Number of instances of '${string}' found: $count\n"; }