in reply to read a file twice...

In addition to the approach involving reading the file into an array as suggested by Chmrr above, I would introduce you to the perlfunc:seek function, which allows you to move the current file read/write pointer within a file. With this command, you can move back to the start of the file and re-read it in full without closing and reopening the file. Eg.

open F, 'filename.ext' or die $!; . . seek F, 0, 0; # Move pointer back to start of file

This approach is advantageous where the file may be particularly large in size and resources may be constrained.