You almost got it. Here is a working version:
#!usr/bin/perl
use strict;
use warnings;
my @data = ( "1\t3", "2\t3", "1\t3", "3\t3", );
foreach my $i (1 .. 3) {
foreach my $j (1 .. 3) {
my $pattern = "$i\t$j";
my $count = grep(/$pattern/, @data);
print $pattern . ($count ? "\t$count\n" : "\n");
}
}