for (@arr1) { #for each element in @arr1 s/\s+$//; #replace one or more spaces at the end of it #with nothing (deleting them) } #### for (@arr1) { while ( substr($_,-1,1) eq ' ' ) { # while the last char is space chop(); # remove the last char } } #### for (@arr1) { chop() while substr($_,-1,1) eq ' ' }