#! /usr/bin/perl use strict; use warnings; my $string = 'this is a test message'; my ($chunk) = $string =~ /(.{1,12})\s/; print $chunk, "\n";