#!/usr/bin/perl use strict; use warnings; my $filename = 'dir/people.txt'; open(my $fh_out, '>', $filename) or die "Could not open file out '$filename' $!"; open(my $fh_in, '<', $filename) or die "Could not open file in'$filename' $!"; # Read in line at a time while( my $line = <$fh_in> ) { # If the file start with blank line replace it with these headers if ( $line =~ /^\S/ ) { print $fh_out, "Name, City, State, Zip"; } } close $fh_in; close $fh_out;