in reply to search pattern and arrays

This code give you the line numbers and each value for the passed phrase : (see output)
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $p = [ q{total Laptops produced:}, q{total mice produced:} ]; sub search_phrase { my $total; $total->{ lc( (split)[1] ) } = undef for @{ $_[0] }; my $i = 1; map { my ( $item, $count ) = (split)[ 1, 3 ]; $item = lc $item; push @{ $total->{$item} }, $i . q{:} . $count if exists $total->{$item}; $i++; } <DATA>; return $total; } print Dumper search_phrase($p); __DATA__ total Laptops produced: 60 total cpu sold: 57 total mice produced: 40 total cpu sold: 45 total Laptops produced: 68 total mice produced: 48 total cpu sold: 51 total printers produced: 19 total monitors produced: 149
Output: $VAR1 = { 'mice' => [ '3:40', '6:48' ], 'laptops' => [ '1:60', '5:68' ] };

hth,
PooLpi