#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Simple; read DATA, my $text, 163; #<- manually grabbed size of DATA just for this example my @matches = ($text =~ /red line.*?location\s+(\d+\.\d+\s+\d+\.\d+)/sg); print Dumper(@matches); __DATA__ A red line is found at location 2.5 4.5 A Blue line is found at location 2.6 4.5 A red line is found at location 2.67 4.56 The red arc is found at location 2.5 4.5