while (my ($match) = m/$regex/g) { $matched{$match} = 1; print "$file $_"; } #### c:\@Work\Perl\monks>perl -wMstrict -le "my $regex = qr{ \b f[eio]e \b }xms; ;; $_ = 'xx fee fie foe yy'; while (m/($regex)/g) { my $match = $1; print qq{captured '$match'}; } " captured 'fee' captured 'fie' captured 'foe' #### while (m/($regex)/g and my $match = $1) { print qq{captured '$match'}; }