#!/usr/bin/perl -w use strict; while (){ s/\s+$//; if (/NEXT LINE MARKER/) { my $nextLine = ; $nextLine =~ s/\s+$//; print "$nextLine\n"; # do stuff with the next line here. } }