#!/usr/bin/perl/ use strict; use warnings; my $key = 'foo'; my $value = 'bar'; my $str = sprintf('%-50s%s', $key, $value); die "wrong pattern: $str" unless $str =~ /^\w+\s+(\w+)$/ and $-[1]==50;