#!/usr/bin/perl use strict; open( my $out_file, '>', "/tmp/outfile" ) or die "Error: Cannot open file\n"; while( my $line = ) { $line =~ s/\s/\|/g; print $out_file "|" . $line . "\n"; } close( $out_file ); __DATA__ 0211121253 Mike Dell ID06533 0211121253 Chris Jones ID02014 0211121253 Pa Kettle ID65255 0111119112 Mitch Poo ID05983