#!/usr/bin/perl -w use strict; print unindent(<<'END'); test test2 END print unindent(<<'END', "(?: {4}|\t)"); test test2 END print unindent(<<'END', ''); I don't want this text to be unindented. END #### sub unindent { my ( $data, $whitespace ) = @_; if ( ! defined $whitespace ) { ( $whitespace ) = $data =~ /^(\s+)/; } $data =~ s/^$whitespace//mg; $data; }