use v5.12; use strict; use warnings; # Obscure but easy way of reading a file into a string to match against... $_ = do { local (@ARGV, $/) = 'loop.txt'; <> }; # Extract text we're interested in... my @matches = m{(.+?)}sg; # Loop through the matches... foreach my $match (@matches) { # This block gets executed for each match! say "GOT: $match"; }