#!/usr/bin/perl use strict; use warnings; while (my $line = ){ chomp($line); $line = "0" . $line while length($line) < 9; my $first = substr($line, 0, 3); my $second= substr($line, 3, 2); my $third = substr($line, 5, 4); my $str = $first . '-' . $second . '-' . $third; print $str . "\n"; } __DATA__ 458430764 453453214 462634878 453990002 462755714 631036456 466917461 467172570 454691673 258611036 42 #### if(length($line) != 9){ warn "Bad data read (at line $.): '$line' length is not correct.\n"; next; # skip processing this line } if ($line !~ /^\d+$/){ warn "Bad data read (at line $.): '$line' not numerical.\n"; next; # skip processing this line }