open my $fh ... etc while (<>) { $line .= $_; if (is_complete_line($line)) { print $fh convert_to_ttf ($line); $line = ''; } } close $fh;