use strict; use warnings; my $modified_string; while ( read DATA, my $buf, 1 ) { $modified_string .= "[$buf]" unless $buf !~ /[a-zA-Z]/; } print $modified_string; __DATA__ this is a test #### use strict; use warnings; my $string = "this is a test"; my $modified_string = $string =~ s/([a-zA-Z])/\[$1\]/gr; print $modified_string;