in reply to SubSearch - "Line starts with"
if the string $SEARCH has any regex special characters in it (like . or * or ()) they will match something unexpected (expect if that is what you want). You can use the function quotemeta() to escape any potential special characters in a string:
$SEARCH= quotemeta($SEARCH);
To anchor a regex to the start of a string you have to start it with ^:
@MATCHING = grep /^$SEARCH/i, @finfo;
But to anchor a regex to the start of a line(!) in a string you have to add a m flag to the regex so that perl knows it is a multiline string (and interprets ^ differently):
@MATCHING = grep /^$SEARCH/im, @finfo;
PS: Dividing a file on empty lines is not what I would call "searching". That did confuse me a bit when I tried to make sense of your question
|
|---|