use warnings; use strict; while(){ chomp; print $1,$/ if/\s+?(\d+?)\/total$/; } __DATA__ Apples Orances:5433 55552246:777449 Country 457852/total Apples Red:9987 green:777449 Public 74585/total