#!/usr/bin/perl use strict; use warnings; for my $temp ("[0-9]blah[0-9]", "[0-9]blah6") { printf "%-15s ", $temp; if ($temp =~ /(\[0-9\])blah\1/) { print "matched\n"; } else { print "didn't match\n"; } }