#!/usr/bin/perl use strict; use warnings; chomp( my $text = ); my $width = 30; my ($rand) = int( ($width - length $text) / 2 ); my $format = ">>%*s%s%*s<<"; print sprintf $format, $rand, ' ', $text, ($width - length($text) - $rand), ' ';