for(@input){ if($_[1] gt $_[2]){ push (@output, "$_[0] $_[2] $_[1] $[3] +"); } print "$_\n" for @output; #### use strict; use warnings; my @input; my @output; while () { push @input, $_; } for (@input) { my @temp = split( /\s+/, $_ ); # you split on a delimiter, which is 1 or more spaces in this case if ( $temp[1] gt $temp[2] ) { push( @output, "$temp[0] $temp[2] $temp[1] $temp[3] +" ); } else { push @output, "$temp[0] $temp[1] $temp[2] $temp[3]"; } } print "$_\n" for @output __DATA__ red 15 2 smith blue 4 10 walter