#!/usr/bin/perl use warnings; use strict; main(); sub main{ # open file my $file = shift @ARGV; open FILE1, '<', $file or die "Can't open '$file': $!"; my %caseCount; # Use a while loop to read through the data while ( ) { my $caseNumber = ( split /\t/ )[ 1 ]; $caseCount{ $caseNumber }++; } # close the file you don't need it any more close FILE1; #do something here with values in %caseCount # DoSomething is an example of how to call a function DoSomething(\%caseCount); } sub DoSomething{ my $hashref = shift; foreach my $key (sort keys %{$hashref}){ print "$key - ${$hashref}{$key}\n"; } }