#!usr/bin/perl-w
use strict;
use warnings;

my %hash = ();
while(<>){
        chomp;
    next if($_ =~ /^@/); ## remove the headers in sam file
        my @s =split;
        my $contig = $s[2];
        $hash{$contig}++;
}

foreach (sort keys %hash){
        print join ("\t", $_,$hash{$_}),"\n";
}