# ... other code while ( ) { # split at whitespaces and ignore leading whitespaces... my @val = split; print out1 join ",", @val; } close inp1; close out1;