#!/usr/bin/perl
use strict;

my @COST = (
['2000','3','6000'],
['3000','4','12000'],
['1000','5','5000'],
['4000','3','12000'],
);

use Data::Dumper;
my ($avarage_cost, $total_pieces, $total_price);
for my $param (@COST) {
my ($unit_cost, $pieces, $price) = @$param;
$total_pieces += $pieces;
$total_price += $price;
$avarage_cost = $total_price / $total_pieces;
print "$avarage_cost\n";
}