Output:use Modern::Perl qw /2014/; use Data::Dump qw /dump/; my @searchstrings = qw/trap hair dog I/; my @found; while (<DATA>) { while ( my ( $index, $search ) = each @searchstrings ) { push @{ $found[$index] }, [ $search, $., $_ ] if /$search/; } } say dump(@found); __DATA__ Transformers robots in disguise I whip my hair back and forth I will catch a dog with a trap
( [["trap", 3, "I will catch a dog with a trap\n"]], [["hair", 2, "I whip my hair back and forth\n"]], [["dog", 3, "I will catch a dog with a trap\n"]], [ ["I", 2, "I whip my hair back and forth\n"], ["I", 3, "I will catch a dog with a trap\n"], ], )
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re: Multiple strings in a file
by CountZero
in thread Multiple strings in a file
by The_Last_Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |