use strict; use warnings; use strict; use warnings; my %triggers; @triggers{qw(bodi forc twice mass acceler law)} = (1); my @UnNum; while () { chomp; next if ! /(\d+),/; push @UnNum, [$1, [split /\s+/]]; } for (@UnNum) { my $count = \$_->[0]; exists $triggers{$_} && ++$$count for @{$_->[1]}; } print join "\n", map {"$_->[0]: " . join ' ', @{$_->[1]}} @UnNum; __DATA__ 81, galileo measur us newton basi law motion 45, galileo experi bodi roll slope act same forc weight effect make constantli speed up 50, show real effect forc chang speed bodi set move previous thought 45, meant bodi act forc keep move straight line same speed