my ($n, $m) = (3, 4); ... $string =~ m{ $rx{$n,$m} }xms and do_something();