$txt =~ s/^(.{1,39}).*$/$1/; or
$txt = substr($txt,0,39); --T -----Original Message----- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik Sent: Thursday, June 30, 2011 11:49 AM To: perl-win32-users@listserv.ActiveState.com Subject: Help with regex I am trying to truncate a string so that it is only 39 characters long. The application is a label printing routine, and the label is only long enough to print 39 characters. I tried this (and many iterations), but it returns the entire string every time. Can anyone see what I'm doing wrong, or maybe suggest a better way? use strict; use warnings; my $txt = 'This is a string that is longer than thirty nine characters used for testing.'; print "\nRunning a test of grabbing the 1st 39 characters of a string.\n"; print "Test string.....: $txt\n"; $txt =~ s/^(.{1,39})/$1/; print "Resulting string: $txt\n"; Barry Brevik _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs