my @file_content = read(file); foreach(@file_content){ if ($_ =~ m/somestring/){ } }