#!/usr/bin/perl use strict; use warnings; use Data::Dumper; ### slurp in the data into our scalar my $data; { local $/; $data = ; } ### if you want to see all the matches my @matches = ($data =~ m/matchingStuffHere[0-9]+/g); print Dumper(\@matches),"\n"; ### only pull the third token my $third_token = ( $data =~ m/matchingStuffHere[0-9]+/g )[2]; print $third_token,"\n"; ### pull the entire line that contains the third token my $third_token_line = ( grep { m/matchingStuffHere[0-9]+/ } split($/,$data) )[2]; print $third_token_line,"\n"; ### kindly donated from fortune __DATA__ Do matchingStuffHere1 you suffer painful elimination? Do you matchingStuffHere2 suffer painful recrimination? Do you suffer painful matchingStuffHere3 illumination? Do you suffer painful hallucination matchingStuffHere4? In order to succeed matchingStuffHere5 in any enterprise, one must be persistent and patient. Saints should always be matchingStuffHere6 judged guilty until they are proved innocent. By trying we can easily learn to endure adversity. Another man's, I matchingStuffHere7 mean.