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