#!/usr/bin/perl while(<>) { chomp; s/^\s+//; s/\s+$//; next if /^$/; #Next if empty... #do something with the text copied to this loop... #just to do something as an example... print "$_ \n"; } #### #1st Example a #input (a) a #output #2nd Example a #input (a newline b pasted to the loop) ba #input and output #press enter b #output #3rd Example a #input (a newline b pasted to the loop) ba #input and output c #input (c) bc #output and output #### a #input a #output a #input (a newline b pasted to the loop) b #continuing a #output b #without pressing enter again