#!/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"; }