#!/usr/bin/perl my %h; my @res; # declare outside the loop open F, $ARGV[0] or die $!; while() { @res = split /\|/; $h{$res[9]}++; } close F; print "$h{$_}\t$_\n" for keys %h; #### #!/usr/bin/perl { local $/; open F, $ARGV[0] or die $!; $all = ; close F; @ips = $all =~ m/^(?:[^\|]+\|){9}([^\|]+)/gm; undef $all; # try to reclaim the memory } my %h; $h{$_}++ for @ips; print "$h{$_}\t$_\n" for keys %h;