I would suggest you write a small function which opens the file and puts the content into a variable. You can pass a file name to open to the function and the content will be returned in @CONTENTS
sub open_file
{
my $FILE = $_[0] ;
open(FILE,"$FILE") or print ("unable to open $FILE file!", __LINE__);
chomp ( @CONTENTS=<FILE>); close FILE;
}
Then you can read the contents from @CONTENTS line by line using foreach loop construct and do the processing with regex.
foreach $LINE ( @CONTENTS )
{
}
This should help you solve the problem.