http://www.perlmonks.org?node_id=575654

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have some code (that works :) ), but it just doesn't feel like the "perl" way to get it done. Can anyone suggest a more elegant way (like putting all of the matches into a variable and only executing the print statement once)?
#!/usr/bin/perl -w use strict; my $regexp = qr{some regexp}o; open (FILE, 'some.file') or die "Can't open file.\n"; undef $/; my $file = <FILE>; close FILE; while ($file =~ /$regexp/g) { print "$1\n"; }