#!/usr/bin/perl $/ = ";\n"; while (my $line = ){ $line =~ s/^#.*[\n\r]*//gm; print "Query: $line" unless $line=~/^\s+$/; } __DATA__ # one comment # two comment # another comment insert into table_name values(1, 'testing 1 2 3'); # more comments insert into table_name values (2, 'test •')