use warnings; use strict; use Test::More; # Retrieve regexes from a text file (or database) as strings, regexify them, # then use them in code my $re_file = 'regexes.txt'; open my $fh, '<', $re_file or die "Can't open $re_file: $!"; my $strings = strings(); my $i = 1; while (my $str_re = <$fh>) { chomp $str_re; my $re = qr/$str_re/; for (@{ $strings->{$i}{match} }) { is $_ =~ $re, 1, "$_ matches $str_re ok"; } for (@{ $strings->{$i}{nomatch} }) { is $_ =~ $re, '', "$_ doesn't match $str_re ok"; } $i++; } done_testing; sub strings { return { 1 => { match => [ qw( a123z az a!$@Zz ), ], nomatch => [ qw( Az aZ a213Z 99 ) ], }, 2 => { match => [ qw( 1 9999 6472323432 ), ], nomatch => [ qw( a1 1a 1! aaaa ) ], }, 3 => { match => [ qw( 2021Z1 2021A1 ), ], nomatch => [ qw( A9 123A9 1234a9 12349 1234A99999999 1234AZ9 ) ], }, }; }