use strict; use warnings; my $data; { local $/ = undef; $data = ; } # my @results = $data =~ m/First Line\nSecond Line\n(\d+)\n/mg; # The m modifier was not really necessary here my @results = $data =~ m/First Line\nSecond Line\n(\d+)\n/g; print join "\n", @results; __DATA__ First Line Second Line 123 First Line Second Line 456 First Line Second Line 789 First Line Second Line 101112 First Line Second Line 131415