if ($val =~ /^([\d]+)\'[b]([01]+)$/) { $strlen = $1; my $binstr = $2; #do things ... } else { print "Wrong kind of input"; }