c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; use Data::Dumper qw(Dumper); ;; my $data = qq{Foo bar -baz boff eid- 1234 gkn 12-34_loanmaster\n} . qq{Fizz :faz foz6 eid - 4532 gkn 34-21-hostmasfer\n} . qq{Do :not capture xeid - 999 gkn 34-21-xxx\n} . qq{Also do :not capture eid999 gkn 34-21-xxx\n} . qq{eid 762 biff bam1 zot@\n} ; print qq{[[$data]] \n}; ;; my $separator = qr{ \s* - \s* | \s+ }xms; ;; my $captured_eids = my @EIDs = $data =~ m{ \b eid $separator \K \d+ }xmsg; ;; if ($captured_eids) { print 'captured EID(s): ', Dumper \@EIDs; } else { print 'no EIDs captured'; } " [[Foo bar -baz boff eid- 1234 gkn 12-34_loanmaster Fizz :faz foz6 eid - 4532 gkn 34-21-hostmasfer Do :not capture xeid - 999 gkn 34-21-xxx Also do :not capture eid999 gkn 34-21-xxx eid 762 biff bam1 zot@ ]] captured EID(s): $VAR1 = [ '1234', '4532', '762' ];