while(){ chomp; next unless /\w/; s/foo/bar/g; say; } while(my $line = ){ chomp $line; next unless $line =~ /\w/; $line =~ s/foo/bar/g; say $line; }