#!/usr/bin/perl -lw my $max = 32767; my $value = "feeefooobarrr"; my $match = ($value =~ /^(.{0,$max})$/); print $match;