while($huge_multi_line_string =~ /ccParty<(\S+)> Port<(\S+)> DTMF<(\S+)>/g){ # do something with $1, $2, and $3 } #### open the file while there are more lines, get a line if the line matches certain strings do something with it close the file