1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env perl use warnings; use strict; my $string = 'hello'; my $allowed = 'a-zA-Z_-'; if ( $string =~ /^([+$allowed]+)\z/ ) { say $1; }
[...]
1
2
3
4
5
6
7
8
9
10
use warnings;
use strict;
use feature 'say';
my $string = 'hello';
my $allowed_char = qr/[+a-zA-Z_-]/;
if ( $string =~ /^($allowed_char+)\z/ ) {
say $1;
}