my @matrix; foreach my $line(@filecontents) { chomp $line; push @matrix, [ split /\s+/, $line ]; } #### $VAR1 = [ [ '0', '48.23', '17.90' ], [ '48.23', '0', '49.58' ], [ '17.90', '49.58', '0' ], [ '59.62', '52.04', '65.80' ], [ '62.20', '56.02', '68.82' ], [ '35.37', '37.87', '36.52' ], [ '27.33', '50.73', '31.85' ] ];