use strict; use warnings; my $totcalls = 0; my @data = ( '2 Active Layer 3 Call(s)',' 4 Active', '12 Active', 'blah', undef, '' ); foreach my $layer3 (@data) { print "INPUT : $layer3 \n"; $totcalls += [ $layer3 =~ m/^\s*([0-9]+) Active/ ]->[0]; print "TOTAL : $totcalls \n"; }