$_ = '1 2=3 4=5'; for my $up_to_3 (/(?:\W*\w+){1,3}/g) { print $up_to_3, "\n"; } #### $_ = '1 2 3 2 6=7 2=4 j=384923 34 43 j 3=6'; for my $foo (/(?:\w[^=]*=\w+)/g) { print $foo, "\n"; }