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

# Define a small square matrix
my @A = (
	 [2, 5, 6, -7, 9],
	 [1, 4, -6, 7, 10],
	 [0, 2, 3, 3, 0],
	 [1, 1, 4, 2, 8],
	 [4, 1, -5, 2, 22],
	 );
my $N = scalar @A;
my $trace = 0;
for ( my $j = 0; $j < $N; $j++ ) {
    $trace += $A[$j][$j];
}
print "The trace is $trace\n";
