window_of_col-2 positions(col-2) sum of col-3 (coverage) based on window --------------- -------- --------------- 1-20 1,4,7 9 21-40 22,24,38 21 41-60 44,50,57,60 85 61-80 65 30 And, I want to print the results as below: window SUM 20 9 40 21 60 85 80 30 #### #!/usr/bin/perl use warnings; use strict; use 5.010; my $total = 0; while (){ chomp; my ($chr, $pos, $coverage) = split /\t/; $total += $coverage; } say $total; #------------------------- #data format: #chr positon_on_DNA coverage __DATA__ chr 1 2 chr 4 2 chr 7 5 chr 22 5 chr 24 6 chr 38 10 chr 44 10 chr 50 20 chr 57 25 chr 60 30 chr 65 30