use strict; use warnings; my $msg = "the quick brown fox jumps over the lazy dog"; my $text = "fox"; my @words = ( ); if ($msg =~ /$text \s (((\w+) \s?)+)/x) { @words = split(/\s+/, $1); # @words now contains the list you want... printf "Words: %s\n", join(',', @words); } __END__ [Results] Words: jumps,over,the,lazy,dog