#!/usr/bin/perl use strict; use warnings; open (FH, '<', 'test.txt') or die "Cannot open 'test.txt' for reading: $!\n"; open (OUT, '>', 'out.html') or die "Cannot open out.html for output: $!\n"; while () { if ( /^# STANDARD/ ){ # Grab the current line. my $first_line = $_; # Grab the line right after it. my $second_line = ; print OUT '

' . $first_line; print OUT '

' . $second_line; } } close FH; close OUT;