use v5.12;
use warnings;
my $Namelist = 'Wilma Fred Barney Betty Dino';
if ( $Namelist =~ m/(\w+a)/ ) {
print "Matched|$<$&$>|\n";
say "The name that matched was $1 \n";
} else {
print "No match: \n";
}
This code results in: Matched|0Wilma0|
The name that matched was Wilma
Note the strange "0" before and after "Wilma". I am in Windows, so I don't get a $< UID or a $> EUID. As I pointed out, those varibles make no sense in the context of trying to print matched output. When I asked what you "what were you trying to do with those", I was trying to get clarification of what you wanted your output to look like. Were you trying to have angle brackets literally used in your output? like: Matched|<Wilma>|
The name that matched was Wilma
That would be accomplished with print "Matched|<$&>|\n";
Or were you trying to have literal dollar signs and literal angle brackets? like: Matched|$<Wilma>$|
The name that matched was Wilma
That would be accomplished with print "Matched|\$<$&\$>|\n";
Or did you just really want Wilma to be printed between the vertical bars? like: Matched|Wilma|
The name that matched was Wilma
That would be accomplished with print "Matched|$&|\n";
Or did you really want the linux user-id number ($<) and effective user-id number ($>) to surround Wilma? like: Matched|###Wilma###|
The name that matched was Wilma
(where ### are actual numbers, not the number-signs I have shown): That would be accomplished with print "Matched|$<$&$>|\n"; |