#!/usr/bin/perl use warnings; use strict; my $test; my $output; open my $INPUT, '<', "file.txt" or die $!; while (<$INPUT>) { chomp $_; s/(\d)-/$1 -/g; open $output, '>>', "test"; printf $output ("%10s \n", "$_"); }