in reply to accessing specific data in a file

... I read the file into an array @lines then did $lines = "@lines" to get a big string

Two things spring to mind about the method you have described here to get your file data into a long string. Firstly, you can achieve the same result in one fell swoop. By unsetting the $/ variable (default input record separator, a newline on *nix) the read consumes the whole file in one go. Make the change local to a small code block to avoid affecting other i/o.

my $lines; { local $/ = undef; $lines = <INPUT>; }

Secondly, there is a potential flaw in your $lines = "@lines"; because interpolating a list in double quotes puts a space character between each element whereas not in quotes doesn't. E.g.

@names = ("bill", "fred", "joe"); print "@names\n"; print @names, "\n";

produces

bill fred joe billfredjoe

For your problem you should have done $lines = @lines; to avoid introducing spaces into the string that weren't in the file.

Cheers,

JohnGG