#!/usr/bin/perl/ use strict; use warnings; use 5.010; my $key = 'foo'; my $value = 'bar'; my $str = sprintf('%-50s%s', $key, $value); say $str; my ($k, $v) = (substr($str, 0, 50), substr($str, 50)); say "'$k'"; say "'$v'"; die "wrong pattern: $str" if ($k !~ s/\s+$// or $v =~ /^\s+/); say "'$k'"; say "'$v'";