use strict; #use warnings; for my $s ( qw( nob bob cob bob dob ) ) { my $name = $1 if $s =~ /(bob)/; warn $name || 'undef'; }