use strict; use warnings; my $restOfLine = q{one fish two fish red fish blue fish}; my @words = $restOfLine =~ m{(\S+)\s+fish}g; print qq{$_\n} for @words; #### one two red blue