#!/usr/bin/perl use strict; use warnings; my @ranges = ('15', '28-31', '3-4', '40', '17-19'); my @totals = (0, 0); foreach my $range (@ranges) { $totals[$_] += (split /-/, $range)[$_] for 0, -1; } print "total is between $totals[0] and $totals[-1]\n";