smoss74 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks, I need to search for a string between two specific character positions in a file. The string is always from character 294 to character 302 in each line of a file containg multiple lines. What is the best way to extract this string? Thanks in advance.
  • Comment on Search for string between specific character numbers in a line

Replies are listed 'Best First'.
Re: Search for string between specific character numbers in a line
by BrowserUk (Patriarch) on May 31, 2010 at 11:48 UTC

    If you are slurping the entire file, use substr:

    if( substr( $file, 294, 6 ) =~ /.../ ) { print 'found'; } else { print 'not found'; }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.