#!/usr/bin/perl
use warnings;
use strict;

my $text = "X4IitemX6Nabc123";
if ($text =~ m/^X(?<namelen>[0-9]+)I(?<name>(??{".{".$^N."}"}))X(?<numlen>[0-9]+)N(?<num>.+)$/) {
    print $text . ": PASS!\n";
} else {
    print $text . ": FAIL!\n"
}
# -> X4IitemX6Nabc123: PASS!