in reply to Tidiest extract or define method?
The m//g (no capture, /g modifier) or m/(...)/ operator returns the empty list in list context on match failure, so one way to do what you want would be as follows (of course, you would replace 'nothing' with '' the empty string):
c:\@Work\Perl\monks>perl -wMstrict -le "for my $string (qw(abcdef ABCDEF xyzzy)) { my ($extracted) = ($string =~ m/cde|ABC/g, 'nothing'); print qq{from '$string' got '$extracted'}; } " from 'abcdef' got 'cde' from 'ABCDEF' got 'ABC' from 'xyzzy' got 'nothing'
|
|---|